Free Support Forum - aspose.com

Sheet.autoFitRows() method is taking a lot of time

Hi,
We are generating excel for one of our modules. The excel sheet is having n sheets. I have invoked
Sheet.autoFitRows() for each sheet. What we encountered that if there are 7 sheets, the total time taken for calls to this particular method is around 24% of the total time of excel generation.What exactly does this particular method do? Can we completely ignore calling this method? Is there any other way we can reduce the time to these calls?

Thanks,
Vimlesh

Hi Vimlesh,

Well, the autoFitRows() method checks each row’s data in the cells of a sheet and then extends/reduces the row height based on the longest/biggest text of a cell in the row. This is a time consuming operation. So, you need to use it carefully for your scenario.
You may try using the overloaded version (as mentioned below) if it reduces the time.

public void autoFitRows(int startRow,
int endRow)

or use autoFitRow() method individually for your specified rows.
Also, kindly try our latest version v2.1.2 if it makes the difference:
http://www.aspose.com/community/files/72/java-components/aspose.cells-for-java/entry221865.aspx


If you still find the issue, kindly post your template file here, we will check it soon.

Thank you.



Hi,
There is one more overloaded method

public void autoFitRows(int arg0, int arg1, int arg2, int arg3)

Is this considering columns as well along with rows?

Would invoking aotoFitRow(int arg0) for desired rows in the sheet improve the performance rather
invoking autoFitRows() method for the whole sheet in one time ?

Thanks,

Hi,

Please note:

The autoFitRows() will adjust the row’s height according to those values of cells of the row, but won’t change the column’s width. For performance, if the specified range (of cells) for autoFitRows(int startRow, int startColumn, int endRow, int endColumn) is much less than the whole data range in the sheet, it will give better performance than using autoFitRows(). If the specified range (of cells) is same or near to the whole data range, there won’t be any difference regarding performance.

And, same is the case with autoFitRow(int), if the desired rows are much less than the rows that contains data in sheet, the performance will be better than autoFitRows(). But if the desired rows are same or near to the rows in sheet, then calling autoFitRow(int) many times will get worse performance than autoFitRows().

Thanks for your understanding!