Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to make POI HSSF support Chinese Encoding?

 
Kevin Qiu
Greenhorn
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);
cell.setCellValue(1);
// Or do it on one line.
row.createCell((short)1).setCellValue(1.2);
//row.createCell((short)2).setCellValue("测试");
row.createCell((short)2).setCellValue(new String("测试".getBytes("ISO8859-1"), "GBK")));
row.createCell((short)3).setCellValue(true);
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
:roll:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic