Editing Microsoft Office Files Using Open XML

To edit MS office files the best approach Available after Office 2007 onwards (when doc files became docx and ppt became pptx and so on) is to use Open Office SDK.

Initially editing doc files required MS Word to be installed on a particular machine but with Open XML format it is not the case. To better Understand how these files work now you can change the extension of the Word file to Zip instead of docx and unzip it. Explore through the files and folders available in the folder and you will get a fair idea about the scenario.

To begin with the demo here.

Say we have a requirement to Add Header to a Word Document or Say Replace the Header of a Word Document. For this requirement we already have a Code in SDK which can help us Out.

For that You can Search “How to: Replace the Header in a Word Processing Document” or go to given Hyperlink which has same code.


Create a Console Application and Add given References and Method to the application.

static void Main(string[] args)
AddHeaderFromTo(@”D:File.docx”, “This is The Header”);

Now here in the method we are passing file “File.docx” and Header “This is Header”.

This will add header to the file.
PS: This code will give exception if the file is not having any data or it is open. Do proper Exception handling for that.

For further reference you can go through sample codes provided by Microsoft.
Sample Code

Leave a Reply

Your email address will not be published. Required fields are marked *