Sunday, January 31, 2010

Approach to fill word/excel documents without Office installed

I've had task where we need to fill our word/excel templates with data from notes documents on Server and get URL to users (our application for web uses only). All users have Office installed but Domino server does not have (and will not have installed it).

So after some research I decided to use the most simple way from my point of view.

Idea is next -> put predefined text (f.x. ##fieldName1##, ##fieldName2##) on word/excel documents and then save them as XML. I did not use bookmark because it is impossible (at least looks like impossible) to process them in XML.

So what do we have at this point? Document saved as XML with predefined text on it.
Then when we need to fill and show document to user we just take our XML template, take all content from it and do many replaces (we replace predefined text on our data from notes document), then don't forget to remove all predefined text that were not filled by some reasons, and then important point print it for web user like this:

Print {Content-Type:application/msword}
Print {Cache-Control: public, must-revalidate}
Print {Expires: Sat, 26 Jul 1997 05:00:00 GMT}
Print xml_output

2 comments :

Stephan H. Wissel said...

A good way to implement such a function is to use the mechanism intended for it: Variables and Ranges. To access them savely you would use the Apache POI library in a Java agent. It will allow you to navigate and update an MS-Office document without risk of "damaging" it. Also you wouldn't run foul of hidden stuff (a word document might contain deleted passages).

Brent Henry said...

Dmytro,

There used to be an issue with earlier versions of Domino whereby the limit of a single print statement was 32k. The print statement also used to append a linefeed that could not be suppressed. The workaround is to break the output up in chunks that end with closing element tags so that the XML doesn't get a linefeed inserted into the middle if an element or attribute name.

This problem existed in R7 and I don't know if it was resolved in R8.x.

If the XML is < 32k then you won't have an issue.