我尝试在 Excel 工作表上应用 autoSizeColumn。我使用的是 POI 3.10.1。
我最后应用 autoSizeColumn 但问题是这个过程太慢/太长:
在工作表上,我大约有 1000 行和 20 列...5 小时后,我终止了该进程...
我不明白什么花了这么长时间,1000 行和 20 列看起来并不那么大:我错过了什么吗? (注意:在较小的文件上,它可以工作)
我的简化代码如下:
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-in Correctly
- 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-lated-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 文件的示例图像,但不知道如何上传。
最佳答案
即使在使用 Apache POI 3.12 后,我也面临着同样的自动调整大小问题。另外,自动调整大小在 Unix/Linux 中不起作用。 我从各个论坛了解到的是: 1.您可以尝试使用SXSSF API,通常工作速度要快得多。 2. 如果没有,则使用 setColumnWidth 方法(我知道它实际上是手动工作 20 列)
关于java - APACHE POI autoSizeColumn 与 useMergedCells 太慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30374248/