我正在通过Open XML SDK 2.0在Word文档中生成新的段落.A具有属性的第一段,我想附加到所有新生成的段落.
像这样的东西:
var _texts = new List<string>() { "Text 1", "Text 2", "Text 1", "Text 4"};
var sdtBlock = wordDoc.MainDocumentPart.RootElement.Descendants<Paragraph>().First();
foreach (string _t in _texts)
{
Paragraph p = new Paragraph();
p.Append(sdtBlock.ParagraphProperties);
p.Append(new Run(new Text(_t)));
sdtBlock.InsertAfterSelf<Paragraph>(p);
}
Run Code Online (Sandbox Code Playgroud)
执行此代码会抛出异常:"无法插入OpenXmlElement"newChild"因为它是树的一部分." 有任何想法吗?