I'm using the Aspose library to create an Excel document. Somewhere in some cell I need to insert a new line between two parts of the text.
I tried "\r\n" but it doesn't work, just displays two square symbols in cell. I can however press Alt+Enter to create a new line in that same cell.
How do I insert a new line programmatically?
To start a new line of text or add spacing between lines or paragraphs of text in a worksheet cell, press Alt+Enter to insert a line break. Double-click the cell in which you want to insert a line break (or select the cell and then press F2).
Try using the [Alt] + [Enter] key. This will create a new line feed in the cell.
We will press the excel shortcut key ALT + ENTER to insert the carriage return character in excel cell. As we press the “ALT + ENTER” key, it pushes the content in front of the selected data to the new line by inserting a carriage return.
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;
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;\">");
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