问题描述
我用下面的code,以自动调整大小在我的小号preadsheet列:
I use the following code in order to autosize columns in my spreadsheet:
for (int i = 0; i < columns.size(); i++) {
sheet.autoSizeColumn(i, true);
sheet.setColumnWidth(i, sheet.getColumnWidth(i) + 600);
}
问题是,它需要超过10分钟自动调整大小在大S preadsheets情况下,每列有超过3000行。这也适用于小型文档速度非常快,但。是否有任何可能有助于自动调整大小的工作速度更快?
The problem is it takes more than 10 minutes to autosize each column in case of large spreadsheets with more than 3000 rows. It goes very fast for small documents though. Is there anything which could help autosizing to work faster?
推荐答案
解决方案,它为我工作:结果
Solution which worked for me:
这是可能避免合并后的地区,所以我可以通过细胞的休息迭代,最后AUTOSIZE到最大的单元格的内容是这样的:
It was possible to avoid merged regions, so I could iterate through the rest of cells and finally autosize to the largest cell content like this:
int width = ((int)(maxNumCharacters * 1.14388) * 256;
sheet.setColumnWidth(i, width);
,其中1.14388是衬线的字体和字体256单位的最大字符宽度。结果
where 1.14388 is a max character width of the "Serif" font and 256 font units.
自动调整大小的性能从10分钟提高到6秒。
Performance of autosizing improved from 10 minutes to 6 seconds.
这篇关于如何加快Apache的POI自动调整大小列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!