การทำงานกับรายการ

รายการในเอกสารMicrosoft Wordคือชุดของคุณสมบัติการจัดรูปแบบรายการ รายการสามารถใช้ในเอกสารของคุณเพื่อจัดรูปแบบจัดเรียงและเน้นข้อความ รายการเป็นวิธีที่ดีในการจัดระเบียบข้อมูลในเอกสารและทำให้ผู้อ่านเข้าใจประเด็นสำคัญ.

แต่ละรายการสามารถมีได้ถึง9ระดับและคุณสมบัติการจัดรูปแบบเช่นสไตล์ตัวเลขค่าเริ่มต้น.

ในAspose.WordsการทำงานกับรายการจะแสดงโดยเนมสเปซLists อย่างไรก็ตามออบเจกต์Listเป็นของคอลเล็กชันListCollectionเสมอ.

หัวข้อนี้อธิบายวิธีทำงานโดยโปรแกรมกับรายการโดยใช้Aspose.Words.

ระบุการจัดรูปแบบสำหรับระดับรายการ

อ็อบเจ็กต์ระดับรายการจะถูกสร้างขึ้นโดยอัตโนมัติเมื่อรายการถูกสร้างขึ้น ใช้คุณสมบัติและเมธอดของคลาสของListLevelเพื่อควบคุมการจัดรูปแบบของแต่ละระดับของรายการ.

รายการรีสตาร์ทสำหรับแต่ละส่วน

คุณสามารถรีสตาร์ทรายการสำหรับแต่ละส่วนโดยใช้คุณสมบัติIsRestartAtEachSection โปรดทราบว่าตัวเลือกนี้ได้รับการสนับสนุนเฉพาะในRTF,DOCและDOCXรูปแบบเอกสาร ตัวเลือกนี้จะถูกเขียนถึงDOCXเฉพาะในกรณีที่OoxmlComplianceสูงกว่าแล้วเอ็กมา 376.

ตัวอย่างรหัสต่อไปนี้แสดงวิธีการสร้างรายการและเริ่มต้นใหม่สำหรับแต่ละส่วน:

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