การทำงานกับการควบคุมเนื้อหาSDT

ในMicrosoft Wordคุณสามารถสร้างฟอร์มได้โดยเริ่มต้นด้วยเทมเพลตและการเพิ่มตัวควบคุมเนื้อหารวม ในAspose.Wordsแท็กเอกสารที่มีโครงสร้างหรือการควบคุมเนื้อหาจากเอกสารใดๆที่โหลดลงในAspose.Wordsจะถูกนำเข้าเป็นโหนดStructuredDocumentTag แท็กเอกสารที่มีโครงสร้าง(SDTหรือการควบคุมเนื้อหา)อนุญาตให้มีการฝังความหมายที่กำหนดไ StructuredDocumentTagสามารถเกิดขึ้นในเอกสารในสถานที่ต่อไปนี้:

  • ระดับบล็อก-ระหว่างย่อหน้าและตาราง,เป็นลูกของร่างกาย,HeaderFooter,ความคิดเห็น,เชิงอรรถหรือโหนดรู
  • แถวระดับ-ในแถวในตารางเป็นลูกของโหนดตาราง
  • เซลล์ระดับ-ระหว่างเซลล์ในแถวตารางเป็นลูกของโหนดแถว
  • แบบอินไลน์ระดับ-ระหว่างเนื้อหาแบบอินไลน์ภายในเป็นเด็กของย่อหน้า
  • ซ้อนกันภายในอีกStructuredDocumentTag

วิธีการตั้งค่าลักษณะการจัดรูปแบบข้อความที่พิมพ์ลงในตัวควบคุมเนื้อหา

ถ้าคุณต้องการตั้งค่าลักษณะของตัวควบคุมเนื้อหาคุณสามารถใช้คุณสมบัติStructuredDocumentTag.StyleหรือStructuredDocumentTag.StyleName เมื่อคุณพิมพ์ข้อความลงในตัวควบคุมเนื้อหาในเอกสารออกข้อความที่พิมพ์จะมีลักษณะ"อ้าง".

ตัวอย่างรหัสต่อไปนี้แสดงวิธีการตั้งค่าลักษณะของตัวควบคุมเนื้อหา:

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>(inputDataDir + u"input.docx");
System::SharedPtr<StructuredDocumentTag> sdt = System::DynamicCast<StructuredDocumentTag>(doc->GetChild(NodeType::StructuredDocumentTag, 0, true));
System::SharedPtr<Style> style = doc->get_Styles()->idx_get(StyleIdentifier::Quote);
sdt->set_Style(style);
System::String outputPath = outputDataDir + u"WorkingWithSDT.SetContentControlStyle.docx";
// Save the document to disk.
doc->Save(outputPath);

การทำงานกับการทำซ้ำส่วนควบคุมเนื้อหา

การควบคุมเนื้อหาส่วนการทำซ้ำช่วยให้การทำซ้ำเนื้อหาที่มีอยู่ภายใน ใช้Aspose.Wordsจะสามารถสร้างโหนดแท็กเอกสารที่มีโครงสร้างของส่วนการทำซ้ำและการทำซ้ำประเภทรายการส่วนและเพื่อจุดประสงค์นี้SdtTypeประเภทการแจงนับให้คุณRepeatingSectionItem.

ตัวอย่างรหัสต่อไปนี้แสดงวิธีการผูกตัวควบคุมเนื้อหาส่วนการทำซ้ำกับตาราง:

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>();
System::SharedPtr<DocumentBuilder> builder = System::MakeObject<DocumentBuilder>(doc);
System::String xml = System::String(u"<books><book><title>Everyday Italian</title><author>Giada De Laurentiis</author></book>") +
u"<book><title>Harry Potter</title><author>J K. Rowling</author></book>" +
u"<book><title>Learning XML</title><author>Erik T. Ray</author></book></books>";
System::SharedPtr<CustomXmlPart> xmlPart = doc->get_CustomXmlParts()->Add(u"Books", xml);
System::SharedPtr<Table> table = builder->StartTable();
builder->InsertCell();
builder->Write(u"Title");
builder->InsertCell();
builder->Write(u"Author");
builder->EndRow();
builder->EndTable();
System::SharedPtr<StructuredDocumentTag> repeatingSectionSdt = System::MakeObject<StructuredDocumentTag>(doc, Aspose::Words::Markup::SdtType::RepeatingSection, Aspose::Words::Markup::MarkupLevel::Row);
repeatingSectionSdt->get_XmlMapping()->SetMapping(xmlPart, u"/books[1]/book", u"");
table->AppendChild(repeatingSectionSdt);
System::SharedPtr<StructuredDocumentTag> repeatingSectionItemSdt = System::MakeObject<StructuredDocumentTag>(doc, Aspose::Words::Markup::SdtType::RepeatingSectionItem, Aspose::Words::Markup::MarkupLevel::Row);
repeatingSectionSdt->AppendChild(repeatingSectionItemSdt);
System::SharedPtr<Row> row = System::MakeObject<Row>(doc);
repeatingSectionItemSdt->AppendChild(row);
System::SharedPtr<StructuredDocumentTag> titleSdt = System::MakeObject<StructuredDocumentTag>(doc, Aspose::Words::Markup::SdtType::PlainText, Aspose::Words::Markup::MarkupLevel::Cell);
titleSdt->get_XmlMapping()->SetMapping(xmlPart, u"/books[1]/book[1]/title[1]", u"");
row->AppendChild(titleSdt);
System::SharedPtr<StructuredDocumentTag> authorSdt = System::MakeObject<StructuredDocumentTag>(doc, Aspose::Words::Markup::SdtType::PlainText, Aspose::Words::Markup::MarkupLevel::Cell);
authorSdt->get_XmlMapping()->SetMapping(xmlPart, u"/books[1]/book[1]/author[1]", u"");
row->AppendChild(authorSdt);
doc->Save(outputDataDir + u"WorkingWithSDT.CreatingTableRepeatingSectionMappedToCustomXmlPart.docx");