We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Autofit Selected Cells

Dear Team,

We are using Aspose.Cells in our application. we have a requirement is to autofit columns based on the contents of specifc cells. Please let us know if this is possible.

We tried to the AutoFitColumns property for a range but the issue is its not autofitting based on the specifed range only its considering the contents in the whole column.

FullDataRange.Worksheet.AutoFitColumns(FullDataRange.FirstRow, FullDataRange.FirstColumn, FullDataRange.FirstRow + FullDataRange.RowCount, FullDataRange.FirstColumn + FullDataRange.ColumnCount)

We have a long description in the header which we dont need to consider while autofit (Basically we need to exclude few cell contents in the column which is not in a specifed range). Is this possible?

Thanks
Anish

Hi,


I have tested your scenario using a sample template file (attached) with v7.5.0.1, it works fine. I have excluded the header cell when auto-fitting a range of cells, i.e. B2:B10.

I have attached the input and output files for your reference and here is my sample code that I am using here.

Sample code:

Workbook workbook = new Workbook(“e:\test2\Bkselectcells.xlsx”);
Worksheet worksheet = workbook.Worksheets[0];

Aspose.Cells.Range sourceRange = worksheet.Cells.CreateRange(“B2:B10”);
sourceRange.Worksheet.AutoFitColumns(sourceRange.FirstRow, sourceRange.FirstColumn, sourceRange.RowCount, sourceRange.ColumnCount);

workbook.Save(“e:\test2\outBkselectedcells.xlsx”);

Thank you.