Archive for Office

Working with Word and OpenXML

When working with Word documents using the OpenXML SDK, it’s not obvious how to remove document protection. The following code shows you how:

using (WordprocessingDocument wordDocument = WordprocessingDocument.Open("[path to Word document]", true))
	DocumentFormat.OpenXml.OpenXmlElement protectedDocElement = wordDocument.MainDocumentPart.DocumentSettingsPart.ChildElements.FirstOrDefault(el => el.XmlQualifiedName.Name.Equals("documentProtection"));
	if (protectedDocElement != null)

Following on from that, it’s also straight forward enough to remove macros from a document (or template):
Read more


Get every new post delivered to your Inbox

Join other followers: