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?
Change the row height to fit the contents Select the row or rows that you want to change. On the Home tab, in the Cells group, click Format. Under Cell Size, click AutoFit Row Height.
Click the Home tab. in the Cells group, click on the Format option. In the dropdown, click on the Row Height option. In the Row Height dialog box, enter the height that you want for each of these selected rows.
Select a row or a range of rows. On the Home tab, select Format > Row Width (or Row Height). Type the row width and select OK.
There are many ways to achieve this.
Don't use wrap or shrink properties on cell values rather include this line just before saving your excel
ws.Columns().AdjustToContents();
Another way is to make use of Allignment property
IXLRange titleRange = ws.Range("B2:AA2");
titleRange.Cells().Style
.Alignment.SetWrapText(true); // Its single statement
Hope it helps!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With