使用useMergedCells的APACHE POI autoSizeColumn太慢了

问题描述 投票:1回答:2

我尝试在Excel工作表上应用autoSizeColumn。我正在使用POI 3.10.1。 我在最后应用了autoSizeColumn,但问题是过程太慢/太长了:在工作表上我有大约1000行和20列... 5小时后,我杀了进程... 我不明白花了这么长时间,1000行和20列看起来不那么大:我错过了什么吗? (nb:在较小的文件上,它正在工作) 我的简化代码如下:

    Workbook vWorkbook = getWorkbook();

    Sheet vSheet = vWorkbook.createSheet("sheet");
    CreationHelper vHelper = vWorkbook.getCreationHelper();
    Drawing drawing = vSheet.createDrawingPatriarch();

    Set<CellRangeAddress> vRegions = new HashSet<CellRangeAddress>();

    //Parcours des lignes du document
    MatrixDocument vMatrixDocument = getMatrixDocument();
    List<MatrixRow> vListMatrixRows = vMatrixDocument.getRows();
    int maxColNb = 0;

    //Parcours des lignes de la grille.
    for (MatrixRow vMatrixRow : vListMatrixRows)
    {
        //(...)
        //create cells 
        //(...)
    }

    initColSpan(vListMatrixRows, vRegions);

    //Gestion des colSpan et des RowSpan
    for (CellRangeAddress vRegion : vRegions)
    {
        vSheet.addMergedRegion(vRegion);
    }

    for (int i = 0; i < maxColNb; ++i)
    {
        vSheet.autoSizeColumn(i, true);//Here the problem. spent more than 5 hour for 1000 lines and 20 columns
    }

我已阅读下面的主题:

    http://stackoverflow.com/questions/16943493/apache-poi-autosizecolumn-resizes-incorrectly
    http://stackoverflow.com/questions/15740100/apache-poi-autosizecolumn-not-working-right
    http://stackoverflow.com/questions/23366606/autosizecolumn-performance-effect-in-apache-poi
    http://stackoverflow.com/questions/18984785/a-poi-related-code-block-running-dead-slow
    http://stackoverflow.com/questions/28564045/apache-poi-autosizecolumn-behaving-weird
    http://stackoverflow.com/questions/18456474/apache-poi-autosizecolumn-is-not-working

但没有人解决我的问题。 任何的想法 ? PS:我试图上传Excel文件的示例图像,但我找不到如何上传它。

java excel performance apache-poi
2个回答
0
投票

即使在使用Apache POI 3.12之后,我也面临着自动调整大小的问题。此外,自动大小在Unix / Linux中不起作用。我从各种论坛中学到的是:1。您可以尝试使用SXSSF API,通常工作得更快。 2.如果没有,那么去setColumnWidth方法(我知道它的字面意思是20列的手工工作)


0
投票

我的解决方案只在最后一行Excel行上使用Autosize,如下所示:

if (i >= abaExcel.Itens.Count)
    sheet.AutoSizeColumn(j);
© www.soinside.com 2019 - 2024. All rights reserved.