Apache POI autoSizeColumn Resizes Incorrectly

前端 未结 8 991
小鲜肉
小鲜肉 2020-11-29 06:27

I\'m using Apache POI in java to create an excel file. I fill in the data then try to autosize each column, however the sizes are always wrong (and I think consiste

8条回答
  •  旧时难觅i
    2020-11-29 07:12

    This is probably related to this POI Bug which is related to Java Bug JDK-8013716: Renderer for Calibri and Cambria Fonts fails since update 45.

    In this case changing the Font or using JRE above 6u45 / 7u21 should fix the issue.

    You can also mtigitate the issue and avoid the columns from being totally collapsed by using a code like this:

        sheet.autoSizeColumn(x);
    
        if (sheet.getColumnWidth(x) == 0) {
          // autosize failed use MIN_WIDTH
          sheet.setColumnWidth(x, MIN_WIDTH);
        }
    

提交回复
热议问题