• Word控件Spire.Doc 【段落处理】教程(六):如何在word文档中设置段落间距


    段落是word文档中非常重要的元素。它功能强大并且具有许多特性。Spire.Doc 是专为开发人员设计的 .NET 组件,可让您轻松灵活地操作段落。

    Spire.Doc for.NET 最新下载icon-default.png?t=M7J4https://www.evget.com/product/3368/download

    我们网站上有介绍如何设置对齐、缩进和项目符号的文档。这篇文章向您介绍了如何在word文档中设置段落间距。

    第一步:创建word文档。

    Document document = new Document();
    Section section = document.AddSection();

    第 2 步:将第一段添加到文档中。

    Paragraph paragraph = section.AddParagraph();
    paragraph.AppendText("Thank you for requesting a trial version of Spire.Doc. The component will work normally except for an evaluation warning message. Once you purchase a license file, the evaluation warning will disappeare.");

    第 3 步:设置第一段的行距。

    paragraph.Format.LineSpacing = 20;

    第4步:设置第一段的间距。

    paragraph.Format.BeforeSpacing = 30;

    第 5 步:设置第一段之后的间距

    paragraph.Format.AfterSpacing = 15;

    第 6 步:保存文档。

    document.SaveToFile("result.doc", FileFormat.Doc);

    完整代码

    using Spire.Doc;
    using Spire.Doc.Documents;
    namespace Spacing
    {
    class Program
    {
    
    static void Main(string[] args)
    {
    Document document = new Document();
    Section section = document.AddSection();
    
    //add the first paragraph
    Paragraph paragraph = section.AddParagraph();
    paragraph.AppendText("Thank you for requesting a trial version of Spire.Doc. The component will work normally except for an evaluation warning message. Once you purchase a license file, the evaluation warning will disappeare.");
    paragraph.Format.FirstLineIndent = 20;
    
    //set the Line spacing
    paragraph.Format.LineSpacing = 20;
    
    //set the Spacing Before
    paragraph.Format.BeforeSpacing = 30;
    
    //set the Spacing After
    paragraph.Format.AfterSpacing = 15;
    
    //add the second paragraph
    Paragraph paragraph2 = section.AddParagraph();
    paragraph2.AppendText("Spire.Doc (Pack) is a compilation of Spire.Doc for .NET, Spire.Doc for Silverlight and Spire.Doc for WPF. It is a professional and powerful Word component which enables you to generate, load, write, edit and save Word document on .NET, Silverlight and WPF. With Spire.Doc, you can create a large range of applications.");
    paragraph2.Format.FirstLineIndent = 20;
    
    //set the Line spacing
    paragraph2.Format.LineSpacing = 25;
    
    //save the document
    document.SaveToFile("result.doc", FileFormat.Doc);
    
    System.Diagnostics.Process.Start("result.doc");
    
    }
    }
    }

    截图

     欢迎加入spire技术交流群:767755948

     

  • 相关阅读:
    使用AWS的API Gateway实现websocket
    SQLite3数据库的介绍和使用(面向业务编程-数据库)
    IceRPC之多路复用传输>快乐的RPC
    Spring的bean装配和bean的自动装配
    【angular】实现简单的angular国际化(i18n)
    Go语言学习基础(二)编写注意,数据类型,关键字,标识符等
    LeetCode每日一题——1582. 二进制矩阵中的特殊位置
    OpenCV之GOTURN目标追踪
    Linus shell 在一个脚本中调用另外一个脚本变量
    Python 数学建模算法与应用
  • 原文地址:https://blog.csdn.net/m0_67129275/article/details/126481467