How to insert programmatically a new line in an Excel cell in C#?
You need to insert the character code that Excel uses, which IIRC is 10 (ten).
EDIT: OK, here's some code. Note that I was able to confirm that the character-code used is indeed 10, by creating a cell containing:
A
B
...and then selecting it and executing this in the VBA immediate window:
?Asc(Mid(Activecell.Value,2,1))
So, the code you need to insert that value into another cell in VBA would be:
ActiveCell.Value = "A" & vbLf & "B"
(since vbLf is character code 10).
I know you're using C# but I find it's much easier to figure out what to do if you first do it in VBA, since you can try it out "interactively" without having to compile anything. Whatever you do in C# is just replicating what you do in VBA so there's rarely any difference. (Remember that the C# interop stuff is just using the same underlying COM libraries as VBA).
Anyway, the C# for this would be:
oCell.Value = "A\nB";
Spot the difference :-)
EDIT 2: Aaaargh! I just re-read the post and saw that you're using the Aspose library. Sorry, in that case I've no idea.
cell.Text = "your firstline<br style=\"mso-data-placement:same-cell;\">your secondline";
If you are getting the text from DB then:
cell.Text = textfromDB.Replace("\n", "<br style=\"mso-data-placement:same-cell;\">");
From the Aspose Cells forums: How to use new line char with in a cell?
After you supply text you should set the cell's IsTextWrapped style to true
worksheet.Cells[0, 0].Style.WrapText = true;