Word組件Spire.Doc 教程:如何在C#中設置段落先後的間距

經過Spire.Doc,咱們能夠在C#中設置段落的格式。 本文將重點演示如何在C#中的段落先後設置間距。ui

將paragraph.AppendHTML()方法添加的新添加的段落的段落先後的間距設置爲新的空白文檔。spa

//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");

圖片1

//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);

圖片2

點擊下載Spire.Docorm

慧都控件網blog

相關文章
相關標籤/搜索