atq

导航

 
XSSFWorkbook wb = new XSSFWorkbook(new File(...));
swb = new SXSSFWorkbook(wb, 100);
SXSSFSheet sheet = swb.getSheetAt(0);

sheet.trackAllColumnsForAutoSizing();
int colSize =  swb.getXSSFWorkbook().getSheetAt(0).getRow(0).getLastCellNum();
for (int i = 0; i < colSize; i++) {
    //模板定义的最小宽度
     int width = sheet.getColumnWidth(i);
     sheet.autoSizeColumn(i);
    //新宽度
     int newWidth = sheet.getColumnWidth(i);
     if (width > newWidth) {
         sheet.setColumnWidth(i,width);
     }
}
posted on 2023-12-22 13:56  atq  阅读(378)  评论(0)    收藏  举报