Word格式处理控件Aspose.Words for .NET教程——创建和编辑列表

本主题描述如何使用Aspose.Words以编程方式使用列表。可以在文档中使用列表来格式化,排列和强调文本。列表是组织文档中数据的一种好方法,它使读者更容易理解要点。

Aspose.Words For .NET是一种高级Word文档处理API,用于执行各种文档管理和操作任务。API支持生成,修改,转换,呈现和打印文档,而无需在跨平台应用程序中直接使用Microsoft Word。此外,API支持所有流行的Word处理文件格式,并允许将Word文档导出或转换为固定布局文件格式和最常用的图像/多媒体格式。

>>Aspose.Words for .NET已经更新至v20.4,Aspose.Words for .Net更新至新版本v20.4,主要新增5大特点,包括:支持阅读PDF文档;提供了更改亚洲段落间距和缩进的功能;为PDF渲染添加了图像插值选项;添加了新的模式3D形状渲染;图表数据标签和系列的扩展API。体验


Microsoft Word文档中的列表是一组列表格式属性。每个列表最多可以具有9个级别,并且分别为每个级别定义了格式设置属性,例如数字样式,起始值,缩进,制表符位置等。List对象始终属于ListCollection集合。

本主题描述如何使用Aspose.Words以编程方式使用列表。可以在文档中使用列表来格式化,排列和强调文本。列表是组织文档中数据的一种好方法,它使读者更容易理解要点。

通过应用列表格式创建列表

Aspose.Words允许通过应用列表格式轻松创建列表。DocumentBuilder提供了DocumentBuilder.ListFormat属性,该属性返回ListFormat对象。该对象有几种方法可以开始和结束列表以及增加/减少缩进量。 Microsoft Word中有两种常规类型的列表:项目符号和编号。

  • 要启动项目符号列表,请调用 ListFormat.ApplyBulletDefault 。
  • 要开始编号列表,请调用 ListFormat.ApplyNumberDefault 。

项目符号或编号和格式将添加到当前段落,并使用DocumentBuilder创建所有其他段落, 直到 调用ListFormat.RemoveNumbers停止项目符号列表格式。 在Word文档中,列表最多可以包含九个级别。每个级别的列表格式指定使用的项目符号或编号,左缩进,项目符号与文本之间的间距等。

  • 要将当前段落的列表级别增加一级,请调用ListFormat.ListIndent。
  • 要将当前段落的列表级别降低一级,请调用 ListFormat.ListOutdent。

下面的示例显示了如何构建多级列表。

Document doc = new Document();DocumentBuilder builder = new DocumentBuilder(doc);builder.ListFormat.ApplyNumberDefault();builder.Writeln("Item 1");builder.Writeln("Item 2");builder.ListFormat.ListIndent();builder.Writeln("Item 2.1");builder.Writeln("Item 2.2");builder.ListFormat.ListIndent();builder.Writeln("Item 2.2.1");builder.Writeln("Item 2.2.2");builder.ListFormat.ListOutdent();builder.Writeln("Item 2.3");builder.ListFormat.ListOutdent();builder.Writeln("Item 3");builder.ListFormat.RemoveNumbers();dataDir = dataDir + "DocumentBuilderSetMultilevelListFormatting_out.doc";doc.Save(dataDir);

重新启动每个节的列表

使用List.IsRestartAtEachSection属性可以重新启动每个节的列表。请注意,仅RTF,DOC和DOCX文档格式支持此选项。仅当OoxmlCompliance高于Ecma376时,此选项才会写入DOCX。下面的代码示例演示如何创建列表并为每个部分重新启动它。

Document doc = new Document();doc.Lists.Add(ListTemplate.NumberDefault);List list = doc.Lists[0];// Set true to specify that the list has to be restarted at each section.list.IsRestartAtEachSection = true;DocumentBuilder builder = new DocumentBuilder(doc);builder.ListFormat.List = list;for (int i = 1; i < 45; i++){   builder.Writeln(String.Format("List Item {0}", i));    // Insert section break.   if (i == 15)      builder.InsertBreak(BreakType.SectionBreakNewPage);} // IsRestartAtEachSection will be written only if compliance is higher then OoxmlComplianceCore.Ecma376OoxmlSaveOptions options = new OoxmlSaveOptions();options.Compliance = OoxmlCompliance.Iso29500_2008_Transitional; dataDir = dataDir + "RestartAtEachSection_out.docx"; // Save the document to disk.doc.Save(dataDir, options);


还想要更多吗可以点击阅读【2019 · Aspose最新资源整合】查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询
标签:

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2020年3月6日
下一篇 2020年3月6日

相关推荐

发表回复

登录后才能评论