翻譯|使用教程|編輯:胡濤|2022-05-26 14:04:50.353|閱讀 341 次
概述:本文主要介紹了如何在 C# 中為 Word 段落添加制表位,歡迎查閱!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
制表位是放置在標尺上的標記,用于定義文本或數字在一行上的對齊方式。要在 Microsoft 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();
截圖:
完整代碼:
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@fc6vip.cn