Apache POI autoSizeColumn() not working right [duplicate]

☆樱花仙子☆ 提交于 2019-12-05 05:12:41

You just need to move the call to

sheet.autoSizeColumn(columnNumber);

to a point in your code after the data has been added.

Here is a link to the API

That's the only way to do it. I had same problem, I was calling the method autoSizeColumn() before I entered the data. Hop it helped

Move the for loop :

for (int j = 0; j < 6; j++) {
                    s.autoSizeColumn(j);
                }

to be just before you write in the workbook and close your out object.

wb.write(out);

Please take note that, if you are generating huge report s.autoSizeColumn(j); will slow down the performance.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!