Monthly Archives: December 2008

Editing Word 2007 XML – choose your tools wisely!

I’m currently involved in a project that involves effectively ‘mail-merging’ and formatting a document based on external data. As certain sections need to disappear and others need to repeat I am actually using an XSL to generate my MS Word document.

However, I’m finding that after each change/iteration I have to look very carefully at the output document. Thus far this is what I’ve found – sometimes when Oxygen XML reformats the XML the ouput Word document contains lots of white space mid-paragraph on long paragraphs. This is due to the <w:t
xml:space=preserve>
tags where the text of the paragraph spans multiple lines. The XML indentation is effectively being shown in Word. Other XML editors will probably have the same issue – BEWARE!

Altova DiffDog is very useful to work out what has changed when things do go wrong with the exception of whitespace issues. Beware though, it doesn’t appear to be able to cope with curved apostrophes or quotes (the type word does for you and aren’t part of ASCII !). Thus if you save any changes you make using DiffDog your Word document will end up full of those pesky empty white boxes signifying strange characters. See below:

Altova DiffDog

Visual Studio 2008

 

Note that Altova XMLSpy does display these characters correctly however I’m now using Visual Studio 2008 (SP1) for editing the XML/XSL and so far so good…

DISCLAIMER: I’m no expert with these things so it’s quite likely I’m missing a setting somewhere, if so please let me know.

Utility to find commands on the Office 2007 Ribbon

Anyone who knows me will know that I am not a fan of the Office 2007 ribbon. For various reasons I now have to use Office 2007 and despite living with it for approx 18months I still can’t always find what I’m looking for on the ribbon….

Step in “Search Commands” from Microsoft Office Labs available at http://www.officelabs.com/projects/searchcommands/

This adds a search ribbon to Office which is actually pretty intelligent checkout the screenshots below:

OK it can’t add functionality that isn’t there…unfortunately.

Creating a Word 2007 document from a template and XML data (or Infopath) programmatically

First things first, I exaggerate a little when I say programmatically what I really mean is not manually! What we’re going to look at is effectively performing a mail-merge without having to use any COM or other API nasties, just the CustomXML support within MS Word. In order to run through this you will need the following:

  1. MS Word 2007 (of course!)
  2. A source XML file, in my case I’m going to use Infopath 2007
  3. The Word 2007 Content Control Toolkit available here
  4. [optional] XML Spy to view what’s going on

The Scenario

You have a standard set of documents that you require customers to fill in at the start of a new engagement, these documents are full of customisations of the customer’s name, order details etc. You would like to generate these documents automatically on a server without having to automate MS Word (!).

You would rather not convert the document to an XSL as the document changes quite frequently and you don’t want the burden of changing the documents each time, a solution whereby the user’s can change the template would be preferable.

The Data Source

There are two categories of data source, the first is the content for the customisations (i.e. customer name) the second are the template documents. For this data source we will use an Infopath form as below:

This should form should be self-explanatory so lets move on to the template word document. In this case we’ll assume the document has been written by someone else and merged in fields have been clearly shown such as:

Now we want to replace the values inside <> with values that come out of our Infopath form. We must now convert the temporary placeholder text for Word Content Controls. We do this by highlighting the text and then selecting the plain text control from the developer toolbar as below:

Next we need to set the properties for our new control by highlighting the control and clicking properties. You should then put some meaningful text in the ‘Tag’ field as you will need this to identify the control later.

Perform this action for all of the fields you wish to populate, where the same field is used you can copy+paste content controls which will retain the same tag. I recommend switching on design mode to ensure you have got all of the controls on and they are tagged correctly giving you something like:

Now let’s complete our InfoPath form and save some data:

Save the output XML file somewhere temporarily as we will need this later. Ensure the word document is closed and open it with the Content Control toolkit:

Note the tags that we applied to the word document are shown, without these you can’t tell the controls apart. Now create a new Custom XML part using the link on the right and switch it to Edit View and you should see:

We must now put our custom XML data from the Infopath form in to the word document. To do this simply open up the XML file from Infopath using the folder icon in the Custom XML parts pane as shown above giving:

Now change to the bind view and drag the fields from the right-pane on to the appropriate control tag on the left:

Save and close the document and re-open in Word and….

…you should have the values from the Infopath form showing inside the Word document. Obviously you’re not going to want to go through this process to generate the document each time, however changing the data now that it is bound is very easy.

Rename the document from “yourdoc.docx” to “yourdoc.docx.zip”, open in explorer and navigate to the ‘CustomXml’ folder and you will see a file called item1.xml

If you double-click that file you will note that it opens in Infopath, thus to change the document ‘data’ you just need to replace the xml file within the word document package each time.

Also I should mention that following the steps above the document is bound “two-ways” that is if you change the clientName field in the Word document not only will all occurrences of that field source change throughout the document but also the xml file will be changed. This behaviour can be changed using the properties of each content control.

Limitations

This type of data merging / generation is only really suitable for simple text insertion, if you have repeating data for example you will probably need to use an XSL approach.

When Web UIs go bad

One of my clients has started using the Eloqua marketing platform and asked me to get involved to build some process around it. I’ve spent a few hours with it now and I have to say that the User Interface is one of the worst I have ever used. A good example is below, in this case I want to import some contacts, so I must first get in to “Database Management”, which if you can’t guess is under the “Evaluate” (wtf!?) menu at the top.

Just look at the number of tabs on that screen, did someone seriously design this? So now where do I find upload? It’s not in that big area in the middle…

No it’s under the contacts ‘menu’ bar. Each menu/drop-down doesn’t have many options under it, many in fact only have one so why aren’t they just visible?

Two of us spent nearly three hours yesterday trying to decipher this along with the program builder. The program builder would be 5 posts on its own! I think one of the issues with this Eloqua system is that on the surface it looks good, and this is bought by marketing people who, let’s be fair like ‘bling’. Unfortunately the system hasn’t been designed for usability and I think it really suffers for it. From what I have seen it is a very powerful system just not an accessible one.