The problem is that the cell content is not wrapped, when that cell contains a formula referring to a cell with some long string.
On CodePlex I found a thread on this issue and a simple code to see the problem:
var generated = new XLWorkbook();
var workSheet = generated.AddWorksheet("Test");
workSheet.Cell("B1").Style.Alignment.WrapText = true;
workSheet.Cell("B1").Value = "hello hello hello hello hello";
workSheet.Cell("A3").FormulaA1 = "B1";
workSheet.Cell("A3").Style.Alignment.WrapText = true;
generated.SaveAs("Generated.xlsx");
I also tried to set row height manually instead of wrapping the cell:
workSheet.Row(3).Height = workSheet.Row(1).Height;
However to no success either.
Is there anything I can do about this?
Following the comment by Peter Albert, I tried to make the set row's AutoFit
. The only thing I managed to find to do this in ClosedXML is workSheet.Row(3).AdjustToContent();
. But this did not work either (neither adjusting the content of certain column).
worksheet.Cell("A3").WrapText = True
followed byworksheet.Row(3).EntireRow.AutoFit
– PrognosisEntireRow
inIXLRow
....I suppose you meantAdjustToContent
?? However this changes nothing. – Shutter.WrapText = True
on cell, that reffers to other cell with long text and it worked for me (cell growed up horizontally). I don't understand your problem... – LollarColumns(A:A).EntireColumn.AutoFit
after each value change. – Lollar