XSSFSheet POI的autoSizeColumn()方法不适用于日文字符

时间:2016-09-21 08:12:44

标签: java excel apache-poi

我使用 Apache POI 进行excel文件导出。但我的问题是 autoSizeColumn()方法对日文字符无法正常工作。 它无法显示整个日语句子。请任何人帮助我: - )

这是我的代码。

public class AutoWidthTest {
public static void main(String[] args) throws Exception {
    XSSFWorkbook workbook = new XSSFWorkbook();
    XSSFSheet spreadsheet = workbook.createSheet("sheet");
    XSSFRow row = spreadsheet.createRow(1);
    XSSFCell cell = (XSSFCell) row.createCell(1);

    cell.setCellValue("日本語日本語日本語日本語日本語");

    spreadsheet.autoSizeColumn(1,true);

    FileOutputStream out = new FileOutputStream(new File("excelBook.xlsx"));
    workbook.write(out);
    out.close();
    System.out.println("excelBook.xlsx written successfully");
}
}

输出结果为:

enter image description here

0 个答案:

没有答案
相关问题