Tom Kurian
Tom Kurian

Reputation: 113

Autosize only Merged Cells using Aspose

I saw that there was a way to autofit rows in the worksheet. But I only want to autofit the rows that have only merged cells in it. And keep all of the other rows the same. Not sure if there is a way to do this.

I've tried this but it autofits all rows.

AutoFitterOptions options = new AutoFitterOptions();
options.AutoFitMergedCells = true;
_worksheet.AutoFitRows(options);

And I won't know the exact row that needs to be autofitted because I'm adding data to the excel sheet.

Upvotes: 0

Views: 115

Answers (1)

Amjad Sahi
Amjad Sahi

Reputation: 1931

Please try the following sample code for your needs:

e.g.

Sample code:

Workbook wb = new Workbook("e:\\test2\\Book1.xlsx");
Worksheet _worksheet = wb.Worksheets[0];
var cells = _worksheet.Cells;
foreach (Cell cell in cells)
{
   if (cell.IsMerged)
   {
        int row = cell.Row;
        AutoFitterOptions options = new AutoFitterOptions();
        options.AutoFitMergedCells = true;
        _worksheet.AutoFitRows(row, row, options);
   }
}

wb.Save("e:\\test2\\out1.xlsx");

Hope, this helps a bit.

You may also post your queries in dedicated forums.

PS. I am working as Support developer/ Evangelist at Aspose.

Upvotes: 0

Related Questions