我已将MainDocumentPart
加载到XmlDocument
对象中,如下所示
using (WordprocessingDocument wdPackage = WordprocessingDocument.Open(fileNameWithPath, true))
{
MainDocumentPart oMainDocPart = wdPackage.MainDocumentPart;
oMainDocPartGlobal = oMainDocPart;
// You must manage namespaces to perform XML XPath queries.
NameTable nt = new NameTable();
XmlNamespaceManager nsManager = new XmlNamespaceManager(nt);
nsManager.AddNamespace("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
if (!(oMainDocPart == null))
{
//XmlNode rootNode = null;
XmlDocument oMainDoc = new XmlDocument(nt);
oMainDoc.Load(oMainDocPart.GetStream(FileMode.Open, FileAccess.Read));
mainDocument = oMainDoc;
mainDocumentElement = oMainDoc.DocumentElement;
mainNamespaceMrg = nsManager;
//save doc
oMainDoc.Save(oMainDocPart.GetStream(FileMode.Create, FileAccess.Write));
}
}
现在,我如何向此XmlDocument
对象添加内容控件。我无法创建SdtBlock
对象并附加到文档正文,而是必须使用此XmlDocument
对象并附加SdtBlock
对象,以便内容控件显示在文档中。