WordprocessingML の「チャンク」を (ドキュメント全体ではなく) Word ドキュメントに追加することは可能ですか? 現在、テンプレートとして使用する docx があります。これには ContentControl が含まれています。AltChunk を介して WordprocessingML のセクションを挿入したいのですが、挿入したコンテンツは、期待どおりにドキュメントに実装されるのではなく、テキストとしてレンダリングされます。
私が現在使用している方法は次のとおりです。
var main = doc.MainDocumentPart;
// Create new AltChunk
string altChunkId = "altChunkId";
AlternativeFormatImportPart chunk = main.AddAlternativeFormatImportPart(AlternativeFormatImportPartType.WordprocessingML, altChunkId);
// Populate altChunk. stream = MemoryStream containing WordprocessingML
chunk.Feed(stream);
// Replace content control with altChunk info
AltChunk altChunk = new AltChunk();
altChunk.Id = altChunkId;
// Get SdtBlock to replace
SdtBlock block = ContentControlHelpers.GetSdtBlock(doc, "ContentControlId");
OpenXmlElement parent = block.Parent;
parent.InsertAfter(altChunk, block);
block.Remove();
挿入しようとしている WordproccessingML のサンプルは次のとおりです (XML + XSLT によって生成されます)。
<w:p>
<w:pPr>
<w:pStyle w:val="heading2" />
</w:pPr>
<w:r>
<w:t>Product 1</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:pStyle w:val="heading3" />
</w:pPr>
<w:r>
<w:t>Europe</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:pStyle w:val="heading4" />
</w:pPr>
<w:r>
<w:t>France</w:t>
</w:r>
</w:p>
<w:document>
これをラップするためにand要素を追加しようとしました<w:body>
が、ドキュメントをしようとしても、ドキュメントに埋め込むのではなく、上に表示されているように、WordprocessingML をテキストとしてレンダリングするだけです。
私がどこで間違っている可能性があるかについて何か提案はありますか?