I am trying to create .xlsx file using apache poi . It is Working fine with arbaric and hindi etc characters . But i in my application we are using chinese characters also. When i am creating .xlsx file using my code only chinese character are not show . I am using this code for creating .xlsx file.
Workbook wb = new HSSFWorkbook(); Sheet sheet = wb.createSheet("new sheet"); // Create a row and put some cells in it. Rows are 0 based. Row row = sheet.createRow(1); // Create a cell and put a value in it. Cell cell = row.createCell(1); //arbaric char set in cell and show successfully in .xlsx cell.setCellValue("سلام"); Cell cell2 = row.createCell(2); **//chinese char set in cell and not show in .xlsx** cell2.setCellValue(" 邓敏 "); Cell cell3 = row.createCell(3); //hindi char set in cell here and show successfully in .xlsx cell3.setCellValue("हिन्दी"); // Write the output to a file FileOutputStream fileOut = new FileOutputStream("workbook5.xlsx"); wb.write(fileOut); fileOut.close();
Can anyone help me how can i write chinese character in .xlsx file using apache poi library . Below i attach .xlsx file output.Thanks in advance
There are some known bugs in Apache POI related to so called “surrogate pairs” in Unicode, see https://bz.apache.org/bugzilla/show_bug.cgi?id=58247 and https://bz.apache.org/bugzilla/show_bug.cgi?id=54084.
Unfortunately it is not easy to fix as it happens deep inside another library. You can try with some other Chinese characters, if some of them work and only some don’t, then it is likely the same issue.
There was some work on fixing the third party lib, see https://bz.apache.org/bugzilla/show_bug.cgi?id=59268, you can try to replace your XMLBeans-jar with the one from http://mvnrepository.com/artifact/com.github.pjfanning/xmlbeans and see if that fixes the problem. If you try then please comment on the bug so we know that it works!