*
The moose likes Struts and the fly likes How to make POI HSSF support Chinese Encoding? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to make POI HSSF support Chinese Encoding?" Watch "How to make POI HSSF support Chinese Encoding?" New topic
Author

How to make POI HSSF support Chinese Encoding?

Kevin Qiu
Greenhorn

Joined: Jan 13, 2002
Posts: 2
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:
 
 
subject: How to make POI HSSF support Chinese Encoding?