Autofit column in ClosedXML.Excel

krabcore picture krabcore · Oct 4, 2016 · Viewed 14.1k times · Source

I understand that the question stupid and from FAQ, but i cant set auto width in excel columns (using ClosedXML.Excel library)

my code:

var wb = new XLWorkbook();
var wsDep = wb.Worksheets.Add("MyWorksheet");
wsDep.Columns("A").AdjustToContents();
wsDep.Columns("B1").AdjustToContents();
wsDep.Columns().AdjustToContents();

but nothing changes. how can i set auto width columns with ClosedXML.Excel library??

Answer

Francois Botha picture Francois Botha · Jan 4, 2017

Your cells don't have any contents.Therefore AdjustToContents() won't have any effect.