Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to make POI HSSF support Chinese Encoding?  RSS feed

Kevin Qiu
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't correctly insert the Chinese Encoding String into Cell. When it's opened by Excel, the words in Chinese are not correct.
The code is following:
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
// Create a row and put some cells in it. Rows are 0 based.
HSSFRow row = sheet.createRow((short)0);
// Create a cell and put a value in it.
HSSFCell cell = row.createCell((short)0);
// Or do it on one line.
row.createCell((short)2).setCellValue(new String("测试".getBytes("ISO8859-1"), "GBK")));
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!