翻譯|使用教程|編輯:胡濤|2022-05-27 13:43:13.357|閱讀 239 次
概述:本文將重點演示如何在 C# 中設(shè)置段落前后的間距,歡迎查閱!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
使用 Spire.Doc,我們可以在 C# 中設(shè)置段落的格式。本文將重點演示如何在 C# 中設(shè)置段落前后的間距。
為新添加的段落設(shè)置段落前后的間距,該段落是通過paragraph.AppendHTML() 方法添加到一個新的空白word 文檔中的。
//create a new word document and add a section and paragraph to it.<font></font> Document doc = new Document();<font></font> Section sec = doc.AddSection();<font></font> Paragraph para = sec.AddParagraph();<font></font> <font></font> //Add the text strings to the paragraph and set the style<font></font> para.AppendHTML("<p>Add a new paragraph to the word and set the spacing</p>");<font></font> para.ApplyStyle(BuiltinStyle.Heading1);<font></font> <font></font> //set the spacing before and after<font></font> para.Format.BeforeAutoSpacing = false;<font></font> para.Format.BeforeSpacing = 20;<font></font> para.Format.AfterAutoSpacing = false;<font></font> para.Format.AfterSpacing = 20;<font></font> <font></font> //save the document to file<font></font> doc.SaveToFile("Result1.docx");<font></font>
using Spire.Doc;<font></font> using Spire.Doc.Documents;<font></font> using Spire.Doc.Fields;<font></font> namespace SetSpacing<font></font> {<font></font> class Program<font></font> {<font></font> <font></font> static void Main(string[] args)<font></font> {<font></font> //create a new word document and load the sample from file<font></font> Document document = new Document();<font></font> document.LoadFromFile("sample.docx", FileFormat.Docx);<font></font> <font></font> //Add the text strings to the paragraph and set the style<font></font> Paragraph para = new Paragraph(document);<font></font> TextRange textRange1 = para.AppendText("This is a inserted paragraph.");<font></font> textRange1.CharacterFormat.TextColor = Color.Blue;<font></font> textRange1.CharacterFormat.FontSize = 15;<font></font> <font></font> //set the spacing before and after<font></font> para.Format.BeforeAutoSpacing = false;<font></font> para.Format.BeforeSpacing = 10;<font></font> para.Format.AfterAutoSpacing = false;<font></font> para.Format.AfterSpacing = 10;<font></font> <font></font> //insert the added paragraph to the word document<font></font> document.Sections[0].Paragraphs.Insert(1, para);<font></font> <font></font> //save the document to file<font></font> document.SaveToFile("Result2.docx", FileFormat.Docx2010);<font></font> }<font></font> <font></font> }<font></font> }<font></font>
歡迎下載|體驗更多E-iceblue產(chǎn)品
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn