Search Here

Custom Search

Sunday, August 19, 2007

Generating Excel using POI in Java

May be you know excel files can be generated from Java by using an API POI.
( to know about POI visit )

When I was using POI to generate excel file I saw a little problem after opening the generated excel file. Suppose I have to display the following text in a cell.

User name: John
Title : Programmer

You see there is a line break between the two lines. That means you have to write “\n” in the code. But when I opened the generated excel I found the two lines were displayed in a single line and there is a garbage box like [] in place of the new line.

But I expected two lines . So what the mistake I did? Can you guess?

Oh shit! I didn’t set the WrapText property of the cellStyle of the Cell.

So, keep in mind to write this

(if the name of the cellStyle of the cell is ’style’.) if your text contains multiple lines.

One more point I observed this problem in MS Office , not in Linux’s Open Office. :-)

No comments: