Aspose excel autofitcolumn but for a certain width

425 Views Asked by At

I want to fit column according to header width not the properties width.Ie Header size should be the column width )

i am using sheet.AutoFitColumns(); which fits according to the max length of cell.

ie pic1

I want to have sheet like this.(Header size should be the column width ie 3b 3c)

pic2

Thank you in advance.

1

There are 1 best solutions below

0
pfx On

That AutFitColumns method has an overload that allows to specify the range upon which to apply the autofit.

public void AutoFitColumns(int firstRow, int firstColumn, int lastRow, int lastColumn)

For your scenario that might be below one (indexes are 0-based) - you might need to adjust.

sheet.AutoFitColumns(2, 1, 2, 2);