Grabbing a non-english character in jexcelapi
-
26-06-2021 - |
Domanda
I have an excel sheet with some non-english characters in it and when I try to grab the contents via
sheet.getColumn(column)[row].getContents()
It returns the string with the replacement character \uFFFD instead of the non-english character which I was going to then translate to unicode using StringEscapeUtils.escapeJava.
//"L\u00F6schen" - correct
return StringEscapeUtils.escapeJava("Löschen");
//"L\uFFFDschen" - incorrect
return StringEscapeUtils.escapeJava(sheet.getColumn(column)[row].getContents());
//"L�schen" - incorrect
System.out.print(sheet.getColumn(column)[row].getContents());
Soluzione
This was really frustrating and it seems that jexcelapi is missing a lot of support.
Went with Apache POI instead and it worked great with no issues.
Altri suggerimenti
Try to set encoding through WorkbookSettings when initializing Workbook. For example:
WorkbookSettings settings = new WorkbookSettings();
settings.setEncoding("Your java charset name");
Workbook workbook = Workbook.getWorkbook(source, settings);
Then getContents() method should correct content of cell
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow