Word组件Spire.Doc 教程:如何在C#中设置段落前后的间距

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

将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 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.Doc

慧都控件网

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
免费Spire.Doc for .NET是e-iceblue公司推出的一款专门对Microsoft Word 文档进行操作的.NET类控件。这款控件的主要功能在于帮助开发人员轻松快捷地生成、编辑和查看Word文档。同时,开发人员还可以通过使用Spire.Doc for .NET 设置Word文档的格式,插入图片,表格,超链接等。Spire.Doc for .NET 最大的便利之处在于它不依赖于Microsoft Word以及任何其他第三方软件。只需将此款控件安装在您的电脑上,您就可以对word文档进行操作。此款控件支持所有的Word格式,即Word97,Word2003,Word2007, Word2010以及Word2013。 主要功能: • 可生成、打开、查看、编辑以及保存Word文档。 • 可对word文档进行加密、解密、设置权限已达到保护Word文档的效果。 • 可对页面进行设置,包括页眉、页脚的设计,插入分页符等。 • 可对文档格式进行设置,包括字体(大小、颜色等)和段落(行间距、项目符号等)的格式设置。 • 可在word文档插入外部资源,如图片、超链接、水印、表格、批注等。 • 支持Word文档和其他文件格式间的转换。如Word to HTML/XML/PDF/EPub/RTF等。同时,其他格式也可以转换为Word,如HTML/XML/RTF/Text to WordWord不同版本间的格式也可相互转换,即Docx to Doc 或者Doc to Docx. • 支持邮件合并功能。开发人员可使用Spire.Doc for .NET提供的邮件合并功能轻松地完成对报表的批量设计及打印。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值