小编Big*_*Man的帖子

使用OpenXml SDK 2.0克隆Word中的ParagraphProperties

我正在通过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"因为它是树的一部分." 有任何想法吗?

c# ms-word openxml openxml-sdk

3
推荐指数
1
解决办法
3301
查看次数

标签 统计

c# ×1

ms-word ×1

openxml ×1

openxml-sdk ×1