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.
Please try the following sample code for your needs:
eg
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.