文檔半島外圍網上直營>>E-iceblue中文文檔>>設置段落前后的間距
                設置段落前后的間距
Spire.Doc for .NET是一款專門對 Word 文檔進行操作的 .NET 類庫。在于幫助開發人員無需安裝 Microsoft Word情況下,輕松快捷高效地創建、編輯、轉換和打印 Microsoft Word 文檔。擁有近10年專業開發經驗Spire系列辦公文檔開發工具,專注于創建、編輯、轉換和打印Word/PDF/Excel等格式文件處理,小巧便捷。
E-iceblue 功能類庫Spire 系列文檔處理組件均由中國本土團隊研發,不依賴第三方軟件,不受其他國家的技術或法律法規限制,同時適配國產操作系統如中科方德、中標麒麟等,兼容國產文檔處理軟件 WPS(如 .wps/.et/.dps 等格式
Spire.Doc for.NET 最新下載
技術交流Q群(767755948)
使用 Spire.Doc,我們可以在 C# 中設置段落的格式。本文將重點演示如何在 C# 中設置段落前后的間距。
為新添加的段落設置段落前后的間距,該段落是通過段落.AppendHTML() 方法添加到一個新的空白單詞文檔中的。
//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產品

 QQ交談
QQ交談 在線咨詢
在線咨詢 
                 
                
 渝公網安備
            50010702500608號
渝公網安備
            50010702500608號
             
            
 客服熱線
客服熱線