星空外围权威网站

Word控件Spire.Doc 【段落处理】教程(十五):在 C# 中为 Word 段落添加制表位

翻译|使用教程|编辑:胡涛|2022-05-26 14:04:50.353|阅读 264 次

概述:本文主要介绍了如何在 C# 中为 Word 段落添加制表位,欢迎查阅!

# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>

相关链接:

制表位是放置在标尺上的标记,用于定义文本或数字在一行上的对齐方式。要在 Microsoft Word 中为段落添加制表位,我们需要打开制表符对话框,然后设置制表位位置、对齐方式和前导符,如下所示。

Spire.Doc for.NET 最新下载

在 C# 中为 Word 段落添加制表位

本文详细介绍了如何使用 Spire.Doc 以编程方式将制表位添加到 Word 文档中的段落。

详细步骤:

第 1 步:实例化一个 Document 对象并向其添加一个部分。

Document document = new Document();
Section section = document.AddSection();

第 2 步:将第 1 段添加到该部分。

Paragraph paragraph1 = section.AddParagraph();

第 3 步:将制表位添加到第 1 段。

//Add tab and set its position (in points)
Tab tab = paragraph1.Format.Tabs.AddTab(28);
//Set tab alignment
tab.Justification = TabJustification.Left;
//move to next tab and append text
paragraph1.AppendText("\tWashing Machine");

//Add another tab and set its position (in points)
tab = paragraph1.Format.Tabs.AddTab(280);
//Set tab alignment
tab.Justification = TabJustification.Left;
//Specify tab leader type
tab.TabLeader = TabLeader.Dotted;
//move to next tab and append text
paragraph1.AppendText("\t$650");

第 4 步:将第 2 段添加到该部分。

Paragraph paragraph2 = section.AddParagraph();

第 5 步:将制表位添加到第 2 段。

//Add tab and set its position (in points)
tab = paragraph2.Format.Tabs.AddTab(28);
//Set tab alignment
tab.Justification = TabJustification.Left;
//move to next tab and append text
paragraph2.AppendText("\tRefrigerator");

//Add another tab and set its position (in points)
tab = paragraph2.Format.Tabs.AddTab(280);
//Set tab alignment
tab.Justification = TabJustification.Left;
//Specify tab leader type
tab.TabLeader = TabLeader.NoLeader;
//move to next tab and append text
paragraph2.AppendText("\t$800");

第 6 步:保存并关闭文档对象。

document.SaveToFile("Tab.docx", FileFormat.Docx2013);
document.Close();

截图

在 C# 中为 Word 段落添加制表位

完整代码

using Spire.Doc;
using Spire.Doc.Documents;
namespace AddTapStops
{
class Program
{

static void Main(string[] args)
{
//Instantiate a Document object
Document document = new Document();
//Add a section
Section section = document.AddSection();

//Add paragraph 1
Paragraph paragraph1 = section.AddParagraph();

//Add tab and set its position (in points)
Tab tab = paragraph1.Format.Tabs.AddTab(28);
//Set tab alignment
tab.Justification = TabJustification.Left;
//move to next tab and append text
paragraph1.AppendText("\tWashing Machine");

//Add another tab and set its position (in points)
tab = paragraph1.Format.Tabs.AddTab(280);
//Set tab alignment
tab.Justification = TabJustification.Left;
//Specify tab leader type
tab.TabLeader = TabLeader.Dotted;
//move to next tab and append text
paragraph1.AppendText("\t$650");

//Add paragraph 2
Paragraph paragraph2 = section.AddParagraph();

//Add tab and set its position (in points)
tab = paragraph2.Format.Tabs.AddTab(28);
//Set tab alignment
tab.Justification = TabJustification.Left;
//move to next tab and append text
paragraph2.AppendText("\tRefrigerator"); //move to next tab and append text

//Add another tab and set its position (in points)
tab = paragraph2.Format.Tabs.AddTab(280);
//Set tab alignment
tab.Justification = TabJustification.Left;
//Specify tab leader type
tab.TabLeader = TabLeader.NoLeader;
//move to next tab and append text
paragraph2.AppendText("\t$800");

//Save and close the document object
document.SaveToFile("Tab.docx", FileFormat.Docx2013);
document.Close();

}

}
}

欢迎下载|体验更多E-iceblue产品

如需获取更多产品相关信息请咨询  


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@atlvshi.cn


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
相关产品
Spire.Doc for .NET

Spire.Doc for .NET 是一款专门对 Word 文档进行操作的 .NET 类库。

Spire.XLS for .NET

Spire.XLS for .NET是专业.NET Excel组件,快速完成对Excel各类编程操作

Aspose.Words for .NET

无需Microsoft Word也可在任何平台上满足Word文档的一切操作需求。

Aspose.PDF for .NET

PDF文档创建组件,无需Adobe Acrobat,也可以在任何平台上操作PDF文档。

VMProtect

新一代软件保护系统,将保护后的代码放到虚拟机中运行,代码反编译软件反破解。

扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP