Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can columns be set to 'autosize' in Excel documents created with NPOI?

Tags:

excel

npoi

NPOI is a .NET port of the Java POI project, which allows one to read and write Microsoft Excel documents (as well as other Office formats). NPOI 1.2.2 has introduced support for 'autosizing' columns, whereby the column is set to the width of the widest cell entry in the column. However, there are many reports that this does not work. So is it possible?

like image 425
Yellowfog Avatar asked Jun 30 '10 17:06

Yellowfog


1 Answers

I've posted this just to answer it, so as to provide a record. It is possible to make columns autosized using NPOI, but you have to add all the data in columns, rather than in rows. Once all the cells have been added to a column @ columnIndex you then call

mySheet.AutoSizeColumn(columnIndex)

and move to the next column. I have found no other way to make this functionality work.

like image 106
Yellowfog Avatar answered Oct 26 '22 19:10

Yellowfog