zoukankan      html  css  js  c++  java
  • 【原创】关于高版本poi autoSizeColumn方法异常的情况

    之前使用的3.9版本,autoSizeColumn方法一切正常,现在切换到了3.15版本这个方法就出先了问题,问题如下,无法自动追踪所有的列。

    Exception in thread "main" java.lang.IllegalStateException: Could not auto-size column. Make sure the column was tracked prior to auto-sizing the column.
        at org.apache.poi.xssf.streaming.SXSSFSheet.autoSizeColumn(SXSSFSheet.java:1606)
        at org.apache.poi.xssf.streaming.SXSSFSheet.autoSizeColumn(SXSSFSheet.java:1560)
        at com.thinkgem.jeesite.common.utils.excel.ExportExcel.initialize(ExportExcel.java:224)
        at com.thinkgem.jeesite.common.utils.excel.ExportExcel.<init>(ExportExcel.java:181)
        at com.thinkgem.jeesite.common.utils.excel.ExportExcel.main(ExportExcel.java:474)
    Caused by: java.lang.IllegalStateException: Cannot get best fit column width on untracked column 0. Either explicitly track the column or track all columns.
        at org.apache.poi.xssf.streaming.AutoSizeColumnTracker.getBestFitColumnWidth(AutoSizeColumnTracker.java:278)
        at org.apache.poi.xssf.streaming.SXSSFSheet.autoSizeColumn(SXSSFSheet.java:1603)
        ... 4 more
    Caused by: java.lang.IllegalStateException: Column was never explicitly tracked and isAllColumnsTracked() is false (trackAllColumns() was never called or untrackAllColumns() was called after trackAllColumns() was called).
        at org.apache.poi.xssf.streaming.AutoSizeColumnTracker.getBestFitColumnWidth(AutoSizeColumnTracker.java:275)
        ... 5 more

    解决如下:

      1.之前使用的是sheet接口,改为SXSSFSheet

      2.在autoSizeColumn前使用sheet.trackAllColumnsForAutoSizing();,手动设置。

     

  • 相关阅读:
    BZOJ 3261 最大异或和(可持久化Trie)
    模板 普通平衡树
    HDU4825 Xor Sum(贪心+Trie树)
    二维LIS(CDQ分治)
    IOIOI卡片占卜(Atcoder-IOIOI カード占い)(最短路)
    USACO 2009 Dec cow toll paths 过路费-floyd
    [USACO08JAN]电话线Telephone Lines(分层图)/洛谷P1948
    lightoj 1038 Race to 1 Again 期望
    lightoj 1030 Discovering Gold 期望
    lightoj 1027 A Dangerous Maze 期望
  • 原文地址:https://www.cnblogs.com/Yiran583/p/6739187.html
Copyright © 2011-2022 走看看