Today, I will show you how to easily open and edit Microsoft Office Open XML files from within Visual Studio. Having worked with Open XML from quite some time, I’ve opened and edited the inner XML of Open XML files (.docx, .pptx, .xlsx) numerous times, though its not too hard to do that, its tiring and cumbersome process (I will write another blog post to tell you how to do that). But I just found a Visual Studio add-on that does that easily.
- Visual Studio 2010
- Open XML Package Editor for Visual Studio 2010. Download from here
Once you have both of above setup properly, you are ready to go. I will show the experience below.
- Make a document/spreadsheet/slideshow file (For our example, I will create a docx shown as below and save it on desktop named “MyTestDocx.docx”).
- Once saved, I will exit word, and open that docx file in Visual Studio 2010.
- I can see something like this,
- document.xml is the file where most of document’s content is stored. If I double click on that, I see some XML but the way Office 2010 saves XML data is all on same line (to save bytes), I can use visual studio’s format document functionality (Edit->Advanced->Format Document OR Ctrl+E,D), I see something as follows,
- To make sure I can change the XML and save the docx from within Visual Studio, I change the term “Test Text here” to “Test Text was here” and save from File menu, and exit Visual Studio. Opening it in Word again, I can see
Though this was a very simple change, the process of editing Open XML file is very simple with the help of OpenXML package editor.