コンテンツコントロールSDTの操作

Microsoft Wordでは、テンプレートから始めて、チェックボックス、テキストボックス、日付ピッカー、ドロップダウンリストなどのコンテンツコントロールを追加して、フォームを作成できます。 Aspose.Wordsでは、Aspose.Wordsにロードされたドキュメントの構造化ドキュメントタグまたはコンテンツコントロールがStructuredDocumentTagノードとしてインポートされます。 構造化ドキュメントタグ(SDTまたはコンテンツコントロール)は、顧客定義のセマンティクスだけでなく、その動作と外観を文書に埋め込むことがで StructuredDocumentTagは、次の場所の文書で発生する可能性があります:

  • ブロックレベル-段落と表の間で、Body、HeaderFooter、Comment、Footnote、またはShapeノードの子として使用されます
  • Row-level-テーブルノードの子としてのテーブル内の行の間
  • Cell-level-テーブル行のセルの中で、行ノードの子として
  • Inline-level-段落の子として、内部のインラインコンテンツの中で
  • 別の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");