标题说明了我遇到的错误。我正在尝试使用 OpenXml隐藏word doc 中的所有文本。目前,当我尝试附加段落属性时,我收到上述错误。我在网上找不到太多关于这个错误的信息。
返回错误的代码
using (WordprocessingDocument wdDoc = WordprocessingDocument.Open(mDoc_copy, true))
{
// Manage namespaces to perform XPath queries.
NameTable nt = new NameTable();
XmlNamespaceManager nsManager = new XmlNamespaceManager(nt);
nsManager.AddNamespace("w", wordmlNamespace);
// Get the document part from the package.
// Load the XML in the document part into an XmlDocument instance.
XmlDocument xdoc = new XmlDocument(nt);
xdoc.Load(wdDoc.MainDocumentPart.GetStream());
MainDocumentPart main = wdDoc.MainDocumentPart;
IEnumerable<OpenXmlElement> elem = main.Document.Body.Descendants().ToList();
Paragraph p;
ParagraphProperties pp = new ParagraphProperties();
ParagraphMarkRunProperties prmp = new ParagraphMarkRunProperties();
Vanish v = new Vanish();
apprmp.AppendChild<Vanish>(v);
pp.AppendChild<ParagraphMarkRunProperties>(apprmp);
foreach (Paragraph para in main.Document.Body.Descendants<Paragraph>().ToList())
{
para.ParagraphProperties = pp;
}
}