Pregunta

I am using Apache POI to create Excel sheets of some records. One such record has 16k rows. I am using a for loop to write records into the excel sheet and in each iteration I am using autoSizeColumn() to auto size the columns. This way I am not able to download/write to the excel file as it is taking forever to complete the writing process. While I was browsing SO, I came across an answer where an user had mentioned that the use of autoSizeColumn() hinders the performance. So, to test that, I removed the autoSizeColumn() and checked, to my wonder it worked fine.

My question - Is it because I am iterating 16k times to auto size the columns, that I am not able complete the writing process? Or does autoSizeColumn() have any performance effects? If so what alternative can I use, in order to write 16k(large number of) records as well as have the columns auto sized to their contents.

Any kind of help is appreciated. Thanks in advance.

¿Fue útil?

Solución

The autoSizeColumn() method does take a lot of time if there are a lot of columns to resize. One solution to this problem is to do call the autoSizeColumn() method for the required column only after all the rows have been created, not in each iteration. The javadoc for this method mentions the following:

This process can be relatively slow on large sheets, so this should normally only be called once per column, at the end of your processing.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top