制表位是放置在标尺上的标记,用于定义文本或数字在一行上的对齐方式。要在 Microsoft 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 alignmenttab.Justification = TabJustification.Left;//move to next tab and append textparagraph1.AppendText("tWashing Machine");//Add another tab and set its position (in points)tab = paragraph1.Format.Tabs.AddTab(280);//Set tab alignmenttab.Justification = TabJustification.Left;//Specify tab leader typetab.TabLeader = TabLeader.Dotted;//move to next tab and append textparagraph1.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 alignmenttab.Justification = TabJustification.Left;//move to next tab and append textparagraph2.AppendText("tRefrigerator");//Add another tab and set its position (in points)tab = paragraph2.Format.Tabs.AddTab(280);//Set tab alignmenttab.Justification = TabJustification.Left;//Specify tab leader typetab.TabLeader = TabLeader.NoLeader;//move to next tab and append textparagraph2.AppendText("t$800");第 6 步:保存并关闭文档对象。
document.SaveToFile("Tab.docx", FileFormat.Docx2013);document.Close();截图:
![]()
完整代码:
using Spire.Doc;using Spire.Doc.Documents;namespace AddTapStops{class Program{static void Main(string[] args){//Instantiate a Document objectDocument document = new Document();//Add a sectionSection section = document.AddSection();//Add paragraph 1Paragraph paragraph1 = section.AddParagraph();//Add tab and set its position (in points)Tab tab = paragraph1.Format.Tabs.AddTab(28);//Set tab alignmenttab.Justification = TabJustification.Left;//move to next tab and append textparagraph1.AppendText("tWashing Machine");//Add another tab and set its position (in points)tab = paragraph1.Format.Tabs.AddTab(280);//Set tab alignmenttab.Justification = TabJustification.Left;//Specify tab leader typetab.TabLeader = TabLeader.Dotted;//move to next tab and append textparagraph1.AppendText("t$650");//Add paragraph 2Paragraph paragraph2 = section.AddParagraph();//Add tab and set its position (in points)tab = paragraph2.Format.Tabs.AddTab(28);//Set tab alignmenttab.Justification = TabJustification.Left;//move to next tab and append textparagraph2.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 alignmenttab.Justification = TabJustification.Left;//Specify tab leader typetab.TabLeader = TabLeader.NoLeader;//move to next tab and append textparagraph2.AppendText("t$800");//Save and close the document objectdocument.SaveToFile("Tab.docx", FileFormat.Docx2013);document.Close();}}}
欢迎下载|体验更多E-iceblue产品
如需获取更多产品相关信息请咨询在线客服
标签:声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!