Tuesday, April 16, 2013

POI - Ordered List and Unordered List ( number list and bullet list )

This is my first week at Amazon. I haven't started any serious coding yet. This is my first itch here. We needed some unordered list ( bullet points ) in one of our program generated word documents. We are using POI.

I thought it should be some simple task. I am hearing about POI from a lot number of years. I was expected some good documentation or forum support. But dude there is none !!

Anyways, this is how I went ahead and have resolved few issues and do have some open questions and looking for answers.

There are two flavors of all the APIs. e.g. HWPF for the old .doc and XWPF for the new .docx. So you better set your game here. Many support you see in forums are for HWPF. Being the newer, I opted for .docx and so choose XWPF.

This is how I found the document structure like:

XWPFDocument  can have multiple XWPFParagraph. XWPFParagraph can have multiple XWPFRun. A XWPFRun is group of words with same formatting.

Open Questions:

1. Why is there not much support for this library? Is there some other library that is being used?
2. The numId is kind of global. i.e. The numbering continues. Also the behavior of this numbering is not clear.
3. Not able to set the level of list. 1, 1.1, 1.1.2
4. How to pick another type of  bullet image.
5. How to number a, b, c, ..

A little explanation would be helpful.

Important: I was struggling with the numId value to get either bullet point or numbers. I created a document and then saved it into .xml to see the structure. I observed variation in value for bullet and numbering. When I created a document from scratch using POI I was not getting the bullets and I was getting only numbers. Then I observed the full xmls, where there are lot of definitions. Somehow ( may be due to encoding ) those definitions were corrupted in case of the document generated from scratch. So I created a document ( can be a template document ) and then used it to write and got the bullet points after 4 hours of work. But feels good.

2 comments:

Manish Arora said...

Hi Amod,

Can you please let me know how you implemented bullets in doc using poi.

THanks,
Manish

Manish Arora said...

I have tried your code but not getting bulleted list