zl程序教程

您现在的位置是:首页 >  其他

当前栏目

Word控件Spire.Doc 【文本】教程(11) ;如何将文本分成两列并在它们之间添加行

教程 如何 添加 控件 11 之间 文本 word
2023-09-11 14:14:49 时间

列被广泛用于设置页面布局,它可以将文本分成两列或多列,以便文本可以在同一页面上从一列流到下一列。使用 Spire.Doc,我们可以实现此功能并同时在列之间添加一条线。本文将介绍如何将文本拆分为两列并在它们之间添加行。

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

注意:请下载最新版本的 Spire.Doc 并添加 Spire.Doc .dll 作为 Visual Studio 的参考。

第 1 步:创建一个新文档并从文件加载

Document document = new Document();
document.LoadFromFile("S.docx");

步骤 2:在第一节添加一列,设置列宽和列间距。这里我们将宽度设置为 100f,间距设置为 20f。

document.Sections[0].AddColumn(100f, 20f);

document.Sections[0].AddColumn(100f, 20f);

第 3 步:在两列之间添加一条线

document.Sections[0].PageSetup.ColumnsLineBetween = true;

第 4 步:保存文件并启动查看效果

document.SaveToFile("result.docx",FileFormat.docx2013);
System.Diagnostics.Process.Start("result.docx");

添加列之前:

效果

完整代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Doc;

namespace Column
{
class Program
{
static void Main(string[] args)
{
Document document = new Document();

document.LoadFromFile("S.docx");

document.Sections[0].AddColumn(100f, 20f);

document.Sections[0].PageSetup.ColumnsLineBetween = true;

document.SaveToFile("result.docx",FileFormat.docx2013);
System.Diagnostics.Process.Start("result.docx");

}
}
}


如有您有产品试用,授权等相关问题,欢迎私聊我获取~