Insert Line Break in Cell

Dec 17, 2010 at 12:00 AM

How do you insert a line break in a cell?

I used to use a char 10 with Excel Interop but that doesn't seem to work with EPPlus.

Coordinator
Dec 17, 2010 at 7:26 AM

This should work...

worksheet.Cells[1, 1].Value = "Row 1\r\nRow2";
worksheet.Cells[1, 1].Style.WrapText = true;
If you dont use C#, \r\n is CRLF,chr(13), chr(10)
Jan
Jul 18, 2013 at 1:40 PM
I am using VB.NET and the above does not work. I found that when I enter chr(10) at the end of a string it also does not work.

The only way I could get it to work was by adding it between two pieces of string:
sheet.cells("A:2:A4").RichText.Add("String that should have a line break" & chr(10))
sheet.cells("A:2:A4").RichText.Add("and does not.")

sheet.cells("A:2:A4").RichText.Add("String that does" & chr(10) & "have a line break")
I found this because I wanted to style the first 'sentance' and then have the rest of the 'paragraph' be a different style.

is this by design or am I doing somehting wrong?
Jul 23, 2013 at 10:30 PM
For VB.NET, you need:
sheet.cells("A:2:A4").RichText.Add("String that does" & chr(13) & chr(10) & "have a line break")