How to get a UTF8 encoded value from a cell object

Hi I’ve existing *.xls file which contains UTF8 encoded values such as Chinese characters. When it’s loaded and opened in memory, loop all cells to get their values.
OutputStream os = new FileOutputStream(“test.csv”);
OutputStreamWriter osw = new OutputStreamWriter(os, “UTF-8”);
BufferedWriter wr = new BufferedWriter(osw);
Cells cells = this.worksheet.getCells();

for (int i = 0; i <= cells.getMaxRow(); i++) {
for (int j = 0; j <= cells.getMaxColumn(); j++) {
Cell cell = cells.getCell(i, j);
String value = cell.getStringValue();
//??? the value is not displayed as Chinese characters???
wr.write(""" + value + “”");
if (j != cells.getMaxColumn()) {
wr.write(",");
}
}
wr.newLine();
}
wr.flush();
wr.close();

Why cell.getStringValue() doesn’t return UTF8 encoded value?

Thanks in advance

Hi,

Could you post your template file here, we will check it soon.

Thank you.

The xls file is attached, it contains Chinese characters (encoded in UTF8).
Thanks.

Hi,

I have logged your issue into our issue tracking system with an id: CELLSJAVA-19720. We will look into your issue and figure it out soon.

Thank you.

Hi,<o:p></o:p>

After further investigation about the issue of generated csv file, I am afraid it is a known issue of JDK that Java's IO api cannot write or read BOM of UTF-8 file correctly. To confirm that, please try following code without any reference to or using Aspose.Cells API:

OutputStream os = new FileOutputStream("test.csv");
OutputStreamWriter osw = new OutputStreamWriter(os, "UTF-8");
BufferedWriter wr = new BufferedWriter(osw);
wr.write("
操作");
wr.write(",");
wr.write("
务项 ID");
wr.newLine();
wr.write("
操作");
wr.write(",");
wr.write("
务项 ID");
wr.flush();
wr.close();


The generated file cannot be shown correctly by MS Excel too. So, in fact the issue has nothing to do with Aspose.Cells. But for saving a workbook as CSV file, I think you can try the API "Workbook.save("test.csv", FileFormatType.CSV)" in which we have handled such situation and the generated csv file can work well with MS Excel. If this api cannot work for you, may be it is because your Aspose.Cells for Java version is too old, please upgrade to our latest versions e.g v2.4.0.

Thank you.


Hi Amjad Sahi,
Thanks a lot. What’s the cost to upgrade one old license for cells?

Hi,

Please post your query (regarding cost to upgrade) in the Aspose.Purchase forum, one of our sales representative would help you soon.

Thank you.