Word控件Spire.Doc 【段落处理】教程(十六):C#中如何设置段落前后的间距

本文将重点演示如何在 C# 中设置段落前后的间距,欢迎查阅!

使用 Spire.Doc,我们可以在 C# 中设置段落的格式。本文将重点演示如何在 C# 中设置段落前后的间距。

为新添加的段落设置段落前后的间距,该段落是通过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>

C#中如何设置段落前后的间距

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>

C#中如何设置段落前后的间距

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

获取更多信息请咨询在线客服  或加入Q群


标签:

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2022年4月24日
下一篇 2022年4月24日

相关推荐

发表回复

登录后才能评论