• Word控件Spire.Doc 【段落处理】教程(十六):C#中如何设置段落前后的间距


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

    为新添加的段落设置段落前后的间距,该段落是通过paragraph.AppendHTML() 方法添加到一个新的空白word 文档中的。

    Spire.Doc for.NET 最新下载(Q群767755948)icon-default.png?t=M85Bhttps://www.evget.com/product/3368/download

    //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("

    Add a new paragraph to the word and set the spacing

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

    using Spire.Doc;
    using Spire.Doc.Documents;
    using Spire.Doc.Fields;
    namespace SetSpacing
    {
    class Program
    {
    
    static void Main(string[] args)
    {
    //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);
    }
    
    }
    }
    

  • 相关阅读:
    Python数据分析与建模库-03数据分析处理库Pandas-1.数据读取
    基于SpringBoot的流浪动物管理系统设计与实现
    蓝桥杯每日一题2023.10.20
    深入浅出Java多线程(九):synchronized与锁
    Linux编译安装libmodbus库
    Vue路由
    9月28日复习
    相机传感器
    jquery基础--学习笔记
    2023年系统规划与设计管理师-第二章信息技术知识
  • 原文地址:https://blog.csdn.net/m0_67129275/article/details/126760229