简体   繁体   English

c# 在 DOCX 中打开 XML SDK 更新附加模板

[英]c# Open XML SDK update attached template in DOCX

I am opening existing .docx files from a SharePoint Document Library over the SharePoint web services, and am attempting to attach a new Template to them.我正在通过 SharePoint Web 服务从 SharePoint 文档库打开现有的 .docx 文件,并尝试将新模板附加到它们。 The current code for this piece seems to not be doing anything at all.这篇文章的当前代码似乎根本没有做任何事情。

XNamespace w = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
OpenXmlPart documentSettingsPart = document.MainDocumentPart.DocumentSettingsPart;
XDocument documentSettingsXDoc = documentSettingsPart.GetXDocument();

documentSettingsPart.AddExternalRelationship("http://schemas.openxmlformats/org/officeDocument/2006/relationships/attachedTemplate", new Uri(_outLibraryTemplate, UriKind.Absolute));

using (XmlWriter xw = XmlWriter.Create(documentSettingsPart.GetStream(FileMode.Create, FileAccess.Write)))
    documentSettingsXDoc.Save(xw);

Does anyone have any thoughts as to why this isn't working - and what I need to do to get this going?有没有人对为什么这不起作用有任何想法 - 以及我需要做什么才能让它继续下去?

This may help.这可能会有所帮助。 It creates a new docx file from a dotx file.它从 dotx 文件创建一个新的 docx 文件。

I modified it a little for my own use - I added the external relationship (a dotm) to an existing file.我对它进行了一些修改以供自己使用 - 我将外部关系(一个点)添加到现有文件中。 Unfortunately I can't work out yet if I can easily programatically update the styles without having to actually open the file.不幸的是,如果我可以轻松地以编程方式更新样式而无需实际打开文件,我还无法解决。

https://web.archive.org/web/20150716111136/http://blogs.msdn.com/b/vsod/archive/2012/02/18/how-to-create-a-document-from-a-template-dotx-dotm-and-attach-to-it-using-open-xml-sdk.aspx https://web.archive.org/web/20150716111136/http://blogs.msdn.com/b/vsod/archive/2012/02/18/how-to-create-a-document-from-a- template-dotx-dotm-and-attach-to-it-using-open-xml-sdk.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM