Работа с контрол на съдържанието 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"); |