0

HSSF Excel 类的字符编码方法似乎已从 3.8 版本中删除。我真的需要至少在单元格上指定编码。API 甚至不再注册编码方法,甚至没有被弃用,尽管它们已经离开了编码的静态字段。

¿ 如何在新的 POI 版本中设置编码?

4

1 回答 1

3

好的,有一种方法可以根据您的需要从您的代码中执行此操作:

//Create the workbook, and the font
HSSFWorkbook wb;
HSSFFont wbFont;
wbFont=wb.createFont();
wbFont.setCharSet(HSSFFont.ANSI_CHARSET); //Your Character encoding goes in the parameter
//Establish cell styles
HSSFCellStyle cellStyle =wb.createCellStyle();
cellStyle.setFont(wbFont);
//We create our cells with our data and with our specified format
HSSFCell cell =null;
cell = row.createCell(1);
cell.setCellStyle(cellStyle);
cell.setCellValue("MY DATA");
//Do the rest for whatever you might need for your workbook and then you create it

请记住,这些类仅适用于 .xls 2003

于 2012-10-25T15:41:38.220 回答