将paragraph.AppendHTML()方法添加的新添加的段落的段落前后的间距设置为新的空白文档。
//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 stylepara.AppendHTML("<p>Add a new paragraph to the word and set the spacing</p>");para.ApplyStyle(BuiltinStyle.Heading1);//set the spacing before and afterpara.Format.BeforeAutoSpacing = false;para.Format.BeforeSpacing = 20;para.Format.AfterAutoSpacing = false;para.Format.AfterSpacing = 20;//save the document to filedoc.SaveToFile("Result1.docx");

//create a new word document and load the sample from fileDocument document = new Document();document.LoadFromFile("sample.docx", FileFormat.Docx);//Add the text strings to the paragraph and set the styleParagraph 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 afterpara.Format.BeforeAutoSpacing = false;para.Format.BeforeSpacing = 10;para.Format.AfterAutoSpacing = false;para.Format.AfterSpacing = 10;//insert the added paragraph to the word documentdocument.Sections[0].Paragraphs.Insert(1, para);//save the document to filedocument.SaveToFile("Result2.docx",FileFormat.Docx2010);

Spire.Doc
控件
标签:文档管理word文档处理
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!