theThought's thoughts

Kevin A Gray - Creative Strategy Guy

Starting the Project to build an OpenXML document

Now I am not suggesting that the articles I am posting are delivering insight on best practice.  I fully expect that as time goes on and I improve my skills that some of the code I write now will be ripped up and re-done.  But I hope that all you out there bothering to read this information will find it helpful in taking the first steps to generating your own solutions.

So, having decided to use VB at the core of my solution and having installed Visual Basic Express 2008.  I created a new project (in this case a Windows Forms based project so that I have a chasis on which to test my classes) and then proceeded to work out what references I needed to include:

Image001

The most critical of these is of course the DocumentFormat.OpenXml, however this only deals with the main xml parts.  The manipulation of the packages is done through System.IO.Packaging which is inferred through the System Reference.  I intend to manipulate XML through the XML DOM as this is a technique I am used to (and I prefer it to simple string manipulation).  As a consequence I have included the System.Xml reference.

Once this is done I create a small and simple Form so that I can run the project and click “start” when I am ready to go.  I will extend this Form as a test chasis to allow me to push sample PASW Data Collection content into the underlying classes to generate the document I need.  The first basic form looks like the one below:

Image002

First Tools in the Box

In order to be able to construct my first example I needed some tools.  Although most of the examples provided are in C# I am not really a C# programmer.  Consequently I decided to use VB and rely on my skills of reading C# code and translating it into VB code.  Luckily some of the examples in the OpenXML 2.0 SDK are VB based.

As I do not have a copy of Visual Studio I opted for the Express versions (Microsoft Express Tools) specifically Visual C# Express 2008 and Visual Basic Express 2008.  

OpenXML files are compressed wrappers for several files and folders.  These outer wrappers are called packages.  It is necessary to be able to view openXML packages in their natural environment (i.e. Office 2007 or later) and then to be able to view the "insides" of these packages to better understand how they work. I already have Office 2007 installed so I had a tool for generating documents that I could reverse engineer.  

OpenXML documents can be opened by Winzip however the following process is required:

  1. Open WinZip
  2. Open the openXML document as an archive
  3. Select the element of the document to be viewed
  4. Right Click and open in either Notepad or an XML viewer

Although I have Winzip I felt that this is a cumbersome process.  A little "googling" revealed a small utility that allows the user the view the insides of a package.  This is called, strangely, PackageExplorer.

Armed with these basic tools I set forth on the expedition of building my first OpenXML package.

Filed under  //   C#   Microsoft   Microsoft Express   Office 2007   OpenXML   OpenXML SDK 2.0   Package Explorer   SPSS   VB   Visual Studio   WinZip