theThought's thoughts

Kevin A Gray - Creative Strategy Guy

OpenXML / PASW Data Collection - Project 1

My presentation at SPSS Directions in Las Vegas (9th – 13th Nov) will require me to provide several working examples of OpenXML / PASW Data Collection integration.  I am currently looking for three different examples with increasing levels of complexity.  Two will probably be around the survey metadata document and Word while the third will be around a reporting script that is exporting to PowerPoint.

So in order to not overwhelm the project and suffer from the inevitable procrastination I have decided to start with a topic that is often requested by clients.

Is it possible to create a printable copy of the responses to a survey so that it can be sent either to the respondent or a stake-holder?

Scenario:
A Rail company wishes to provide an online complaints form that allows travellers to submit details of complaints regarding late trains or poor service while on trains.  The information would then be escalated to the relevant account manager with the complainant receiving a copy of the details of the complaint for their own records.

The Survey:
This will consist of two pages of questions.  The first will obtain general details of the complainant while the second will obtain details of the complaint.  Once both pages have been captured the complainant will be asked to confirm submission and then will be e-Mailed a PDF copy of the complaint.  Their e-Mail address is a mandatory field in the first page.

The Steps:
The following steps will be required to complete the project:

·         Construct Survey Metadata

·         Construct Survey Routing to ask questions

·         Watch Microsoft Videos on Custom Parts

·         Build Routing to construct an XML document of the responses provided

·         Construct a Word document defining the layout of the complaint record form

·         Pass the XML across to the document as a Custom Part

·         Insert Placeholders into the document to ensure the information appears in the right locations in the document

·         Create a dll that receives the XML from PASW Data Collection, inserts it into the custom part within the document template, generates a PDF from the resulting document and sends it to the complainant

These steps have been defined before I have had chance to watch the videos on the implementation of custom parts.  I am documenting my intentions at this point so that I can show what has to change once I better understand the way custom parts work.

Filed under  //   Custom Part   Metadata   OpenXML   OpenXML SDK 2.0   PASW DATA Collection   Routing   SPSS   SPSS Directions  

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

Three Critical Parts to an OpenXML package

So the first thing to learn is the basic, underlying structure to an openXML document whether it is for Word, Excel or Powerpoint.  Each document is a compressed collection of XML documents wrapped into a single file.  Each of these XML documents is called a “part” while the wrapper is called a package.

When a new package is created it must consist of three core elements:

·         A MainPart – this is the main document being created

·         A CollectionTypes Part – this describes the types of parts that are included in the document (Word, Excel, Powerpoint, image, video etc)

·         A relationships part – this defines the relationships between each part

A package must contain all three, if it does not then it is not considered a valid package, it is effectively just a WinZip file with a funny extension.

The easiest way to see this is to perform the following steps:

1.       Open Word 2007 (or later)

2.       Enter a single line of text

3.       Save the document as a DOCx file

4.       Close the document

5.       Open Winzip

6.       Select Open Archive from the File menu

7.       Point to the DOCx file

8.       Click OK

The following figure shows what the zip file should look like.

Fig_1

As can be seen from this image there are three files in the package.  The first is the relationships file (.rels) this sits is a sub-folder off the root of the document.  The second is the content types document and the last is the main part of the document that contains the content of this document.  Each of them is a well formed XML document.

In version 1.0 of the openXML SDK each of these parts would have to be created manually then placed together into a single compressed file.  In version 2.0 of the openXML SDK there are methods that allow the rapid creation of these three documents by simply creating the main part document.

Filed under  //   ContentTypes   DOCx   Excel   MainPart   OpenXML   OpenXML SDK 2.0   Package   PowerPoint   Relationships   SPSS   WinZip   Word 2007  

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