使用列表
Microsoft Word文档中的列表是一组列表格式属性。 列表可以在文档中用于格式化、排列和强调文本。 列表是在文档中组织数据的好方法,它们使读者更容易理解关键点。
每个列表最多可以有9级别和格式属性,如数字样式、开始值、缩进、标签位置等都是为每个级别单独定义的。
在Aspose.Words中,使用列表由Lists命名空间表示。 但是,List对象始终属于ListCollection集合。
本主题介绍如何使用Aspose.Words以编程方式处理列表。
指定列表级别的格式
创建列表时会自动创建列表级对象。 使用ListLevel类的属性和方法来控制列表各个级别的格式设置。
每个部分的重新启动列表
您可以使用IsRestartAtEachSection属性重新启动每个部分的列表。 请注意,此选项仅在RTF、DOC和DOCX文档格式中受支持。 只有当OoxmlCompliance高于Ecma376时,此选项才会写入DOCX。
下面的代码示例演示如何为每个部分创建一个列表并重新启动它:
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
System::SharedPtr<Document> doc = System::MakeObject<Document>(); | |
doc->get_Lists()->Add(ListTemplate::NumberDefault); | |
System::SharedPtr<List> list = doc->get_Lists()->idx_get(0); | |
// Set true to specify that the list has to be restarted at each section. | |
list->set_IsRestartAtEachSection(true); | |
System::SharedPtr<DocumentBuilder> builder = System::MakeObject<DocumentBuilder>(doc); | |
builder->get_ListFormat()->set_List(list); | |
for (int32_t i = 1; i < 45; i++) | |
{ | |
builder->Writeln(System::String::Format(u"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.Ecma376 | |
System::SharedPtr<OoxmlSaveOptions> options = System::MakeObject<OoxmlSaveOptions>(); | |
options->set_Compliance(OoxmlCompliance::Iso29500_2008_Transitional); | |
System::String outputPath = outputDataDir + u"WorkingWithList.SetRestartAtEachSection.docx"; | |
// Save the document to disk. | |
doc->Save(outputPath, options); |