RSS

Documents and Spreadsheets with XPages – the Idea (Part I)

07 Sep

In several projects we are faced with the request to export data to a spreadsheet (mostly excel) or build a document for ms-word. So our development team requested the following: “Build an extension that helps us generate word documents or export datasets to spreadsheets”.
After some research, I found a project called Apache POI.

Apache POI covers all the stories, which we try to implement. So let’s begin with the first story: “Generating a new ms-word document”.
The story is very simple, but also very powerful. In our example the starting point is a document like the OpenNTF Contributor License Agreement. This document is needed for a company to contribute code to OpenNTF. Typically, this document has some lines (fields), which you have to fill in with your values.  Let’s try to automate this process. We will build a form in the XPages application, where you can fill in your company name, address and other things. Then we modify the standard OpenNTF form a little bit, as you can see on the screenshot below:


In your XPages form we implement the new POI Document element and then we do some wiring:

  1. We define where the modified OpenNTF Licence Agreement is. This could be a file resource in the application, or a document accessible via view and a predefined key.
  2. Defining “Bookmarks”:
    As you see on the word document, we have defined several “<<NAME OF BOOKMARK>>” tags in the text. This text must be in the same style, so they are in the same “run” Element on the document.
  3. In our “POI Document” – Control could we now define a bookmark for each <<…>> element, which contains the name and a value.
  4. As you see, the value can be computed (so a binding to a viewScope variable is possible)
  5. We define a “download” button and connect the onClick event on a new action called “Generate Document”

The user can now fill in their values on the page and generate a customized word document.  Developers are able to build in applications to produce customized documents in a very short time.
In the next blog entries, we will show you how we have build an extension of this function.

 

Tags: , , , ,

12 responses to “Documents and Spreadsheets with XPages – the Idea (Part I)

  1. Rajesh

    September 7, 2012 at 10:29 pm

    Hi Christian,
    NIce article and good explanation.
    Can the same technique use for importing xls and word document where there is no MS word or excel is installed on the server?

     
    • guedebyte

      September 7, 2012 at 10:34 pm

      Yes. The 3. userstorie will cover the import of an excel file. Our beacon award finalist application use the import technic already. The hard job is now to find a way, how we can make this configurable in a XPages component, but we are working on that.

       
  2. guedebyte

    September 11, 2012 at 8:32 pm

     
  3. Matt

    September 13, 2012 at 8:17 pm

    As a novice XPage developer I was wondering how you have put the ‘Apache POI Document’ control together. Can you explain?

     
    • guedebyte

      September 13, 2012 at 8:21 pm

      I will document this in the next blog entries. It will cover how we build the kernel for the documentprocessing and the controlls. The full code with the source will be contributet to openNTF later this year (befor the openNTF context ends).

       
  4. setebos

    March 3, 2013 at 9:36 pm

    I have tried to use the Xpages POI feature into our project. It works very well. But i have found out, that if using generating word document from the template document, it has to be the new docx or dotx form, not the old word 97-2003 form (.doc).

    I have got this error:

    POI 4 XPages -> ERROR
    ————————————————————–
    Error : Error during Documentgeneration
    POI LIB : 1.1.5.201302211421
    StackTrace:
    java.lang.NullPointerException
    at biz.webgate.dominoext.poi.component.kernel.DocumentProcessor.processBookmarks2Document(DocumentProcessor.java:76)
    at biz.webgate.dominoext.poi.component.kernel.DocumentProcessor.processDocument(DocumentProcessor.java:200)
    at biz.webgate.dominoext.poi.component.kernel.DocumentProcessor.generateNewFile(DocumentProcessor.java:146)

    Is this restriction true, or should i set some other params? Thanx.

     
    • guedebyte

      March 4, 2013 at 8:06 am

      Hello

      Yes we can only handle docx document in the actual relase. If the older format is also needed let us know and we make a evaluation if we can offer the same functionality.

      Best regards
      Christian

       
  5. ebors

    March 4, 2013 at 6:52 pm

    Thanx, thats fine for now.

    I have tried this generating the word in IE 9, and the Xpage sends the ZIP file. Have you any experience with it?

     
  6. ebors

    April 20, 2013 at 2:04 pm

    Hallo, hatten Sie die Zeit, das Problem mit MimeType anzuschauen? Danke.

     
    • guedebyte

      June 12, 2013 at 3:13 pm

      Wir konnten das Problem reproduzieren, die neuste Version auf openNTF hat einen entsprechenden Fix

       

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: