原創(chuàng)|使用教程|編輯:王香|2017-11-13 11:58:19.000|閱讀 930 次
概述:Spire.Doc 是一個(gè)MS Word 組件,用戶可以直接執(zhí)行各種Word文檔處理任務(wù), 分為.NET、WPF和Silverlight 三個(gè)版本,本文介紹了如何通過Spire.Doc在如何在C#中設(shè)置段落前后的間距。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
通過Spire.Doc,我們可以在C#中設(shè)置段落的格式。 本文將重點(diǎn)演示如何在C#中的段落前后設(shè)置間距。
將paragraph.AppendHTML()方法添加的新添加的段落的段落前后的間距設(shè)置為新的空白文檔。
//create a new word document and add a section and paragraph to it. Document doc = new Document(); Section sec = doc.AddSection(); Paragraph para = sec.AddParagraph(); //Add the text strings to the paragraph and set the style para.AppendHTML("<p>Add a new paragraph to the word and set the spacing</p>"); para.ApplyStyle(BuiltinStyle.Heading1); //set the spacing before and after para.Format.BeforeAutoSpacing = false; para.Format.BeforeSpacing = 20; para.Format.AfterAutoSpacing = false; para.Format.AfterSpacing = 20; //save the document to file doc.SaveToFile("Result1.docx");
//create a new word document and load the sample from file Document document = new Document(); document.LoadFromFile("sample.docx", FileFormat.Docx); //Add the text strings to the paragraph and set the style Paragraph para = new Paragraph(document); TextRange textRange1 = para.AppendText("This is a inserted paragraph."); textRange1.CharacterFormat.TextColor = Color.Blue; textRange1.CharacterFormat.FontSize = 15; //set the spacing before and after para.Format.BeforeAutoSpacing = false; para.Format.BeforeSpacing = 10; para.Format.AfterAutoSpacing = false; para.Format.AfterSpacing = 10; //insert the added paragraph to the word document document.Sections[0].Paragraphs.Insert(1, para); //save the document to file document.SaveToFile("Result2.docx",FileFormat.Docx2010);
慧都控件網(wǎng)
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn