Greetings o-helpful-poiers:
Alright so here goes, I am having an encoding issue and not a straight forward one.
I am working on win xp pro, English U.S. with no language packs installed and with all the service packs and fixes. I am using jdk 1.4.2_03


I have this text in my Excel file:

EMBARCACIONES INSCRITAS EN EL REGISTRO NACIONAL DE PESCA DEL SECTOR SOCIAL EN PESCA RIBERE�A SEG�N PESQUER�A Al 31 de diciembre de 1993

I get it out of the spreadsheet using POI and then want to print it in UTF-8 so I call this function

private String convertToUTF8(String incoming){
       String outgoing = null;
       try {
          if(incoming != null){
               byte[] incomingBytes = incoming.getBytes("UTF-8");
               outgoing = new String(incomingBytes);
          } else {
              outgoing = "";
          }

} catch (UnsupportedEncodingException e) {
logger.error(" threw an exception trying to write utf8:" +e.getMessage());
}
return outgoing;
}


And what I get when I put it in XML is this:

<titl> CUADRO 4.1.4.4 - EMBARCACIONES INSCRITAS EN EL REGISTRO NACIONAL DE PESCA DEL SECTOR 
SOCIAL EN PESCA RIBERE�A SEG�N PESQUER�A Al 31 de diciembre de 1993</titl>

Notice what happened to the �, it got turned into a �


I checked the binary hex in the excel file at that location and its value is CD which is the right binary hex for �.


So I don't understand why some characters are being converted and just that one character is not. And its consistent among spreadsheets that the � is not converted while other accented characters are.
I tried using some of the code from this page
http://www.jguru.com/faq/view.jsp?EID=137049
but then none of the character are being rendered correctly.


Here is how I am getting the cell's contents with POI

private String cellToString(HSSFCell cell){
       String value = null;

       if (cell == null ) {
           value = "";
       } else if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING){
           value = cell.getStringCellValue();
       } else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){
           value = Double.toString(cell.getNumericCellValue());
       } else if (cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
           value = "";
       } else if (cell.getCellType() == HSSFCell.CELL_TYPE_BOOLEAN){
           boolean bvalue = cell.getBooleanCellValue();
           value = Boolean.toString(bvalue);
       } else if (cell.getCellType() == HSSFCell.CELL_TYPE_FORMULA){
           value = cell.getStringCellValue();
       } else {
           value = "";
       }

       return value;
   }


Any help or suggestions would be greatly appreciated since I am not sure about how to dig into the POI library to see what is happening there.
Thanks,
Steve


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to