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
No comments:
Post a Comment