Showing posts with label Block characters in excel sheet using jxl api java. Show all posts
Showing posts with label Block characters in excel sheet using jxl api java. Show all posts

Thursday, March 3, 2011

Generating xlsx excel 2007 files using jdk 1.4

Hi,

i need to generate excel 2007 reports in java, well, i had many options to do this like Jexcel, apache poi, Aspose...but this list got smaller since i had to do this in jdk 1.4,  since i had to do this in older jdk, i chose apache poi, but apache poi supports generating xlsx only on jdk 1.6, some blogs says that if we backport then poi can work on older jdk's, so i tried backporting it and converted jars in jdk 1.4, all was done and it worked for generating xls files, but when i changed it for xlsx using XHSSF class, it started throwing errors, i did lot of research but at the end, all was in vain. later on i read somewhere that apache poi backporting leads to serious memory issues on jdk 1.4, so i had gone for Jexcel, well jexcel needs a license and i gotaa use open source so i winded up this idea.

Finally, i had chosen Apache POI with Jdk 1.6 and its working great.

Cheers!!

Ujjwal

Thursday, October 28, 2010

Block characters in excel sheet using jxl api java

Hi,

Today one of my project which was getting used in Serbia started giving a problem, users started complaining that they are getting square block characters between text. Now, this problem was due to different character-set which was handled upto a certain extent when i initially developed this project. I tried all sorts of things to handle this issue and finally i came up with a solution below :

 if(myText!=null)
 {
 label = new Label(0, a, "Header", cellFormat1);
 sheet5.addCell(label);


a=a+1;  

                                                
if(myText.substring(myText.length()-1, myText.length()).equals("\n"))
{
                                                   
 label = new Label(0, 1, myText.replace('\r',' ').replaceAll("[^\\p{ASCII}]",""), myCellFormat);
 sheet5.addCell(label);


}//end of sub-if
//end of main-if








//end of code


************here's the explanation for the code*********

1) [^\\p{ASCII}]

This says "replace all occurences of one or more non-ASCII characters with nothing." So the new string will be the old string minus all non-ASCII characters. You just check the new String's length.

Or you could just iterate over the string, checking if each char is between 0x00 and 0x7F.





2) '\r'
This was for removing carriage returns which were getting displayed in my excel sheet as block characters   

Finally, at the end of my day, this issue got resolved and for multiple countries this issue got resolved.

Regards,

Ujjwal Soni