I'm trying to write Unicode characters into an Excel file. I did it successfully with Unicode plane 0, but not with Unicode plane 1.
I use POI 3.16 and use this simple piece of code to test :
public void createFile() throws IOException {
SXSSFWorkbook workbook = new SXSSFWorkbook(1);
SXSSFSheet sheet = workbook.createSheet("data");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
String value = "💩💩💩ᚬᚬᚬ";
cell.setCellValue(value);
try (FileOutputStream fop = new FileOutputStream("C:\\Users\\Emilien\\PROJECTS_FILES\\BUGS\\SLIMS_14124\\test.xlsx")) {
workbook.write(fop);
} finally {
workbook.dispose();
}
}
In excel 2016, the cell contains "??????ᚬᚬᚬ" instead of displaying "💩💩💩ᚬᚬᚬ". Find URLs about characters here ᚬ and here 💩.
I unzipped the excel file and investigated the content of sheet data, the XML content corresponding to the cell is :
<row r="1">
<c r="A1" t="inlineStr"><is><t>??????ᚬᚬᚬ</t></is></c>
</row>
As we can see, the plane 0 characters have been converted into HTML Unicode characters, while the plane 1 characters have been lost.
If I change "??????" by "💩💩💩" in the XML file, and compress the files into a new xlsx file again, the characters are rendered as wanted (meaning, the cell actually contains 💩💩💩ᚬᚬᚬ).
It seems like the Java Strings are not written into the XML as UTF-8, but seem to be processed by POI (we end up with HTML characters). Has anyone experienced this before ? Is it possible to write SMP characters into an Excel file ?
Could it be a bug ? I mean, the XML files declare a UTF-8 encoding in their header but don't seem to respect it. Am I missing something ?
<?xml version="1.0" encoding="UTF-8"?>
xmlbeans-2.6.0.jar
. Do using a newer version.