0

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.

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.