Search code examples
c#closedxml

Using ClosedXML how to adjust row height to content?


I create cell with text. After that I set WrapText property and column width.

var cell = worksheet.Cell("A1");
cell.Style.Alignment.WrapText = true;
cell.SetValue("This is very long text");
worksheet.Column(1).Width = 10;
worksheet.Rows().AdjustToContents();

The text has been moved by words, but row height is not changed. How to adjust row height to cell content?


Solution

  • It works when you remove the worksheet.Rows().AdjustToContents();.

    Autofitting sometimes needs more of a trial and error approach ...