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 i
SpreadsheetGear for .NET does it this way:
IWorkbook workbook = Factory.GetWorkbook();
IRange a1 = workbook.Worksheets[0].Cells["A1"];
a1.Value = "Hello\r\nWorld!";
a1.WrapText = true;
workbook.SaveAs(@"c:\HelloWorld.xlsx", FileFormat.OpenXMLWorkbook);
Note the "WrapText = true" - Excel will not wrap the text without this. I would assume that Aspose has similar APIs.
Disclaimer: I own SpreadsheetGear LLC
Using PEAR 'Spreadsheet_Excel_Writer' and 'OLE':
Only way I could get "\n
" to work was making the cell $format->setTextWrap();
and then using "\n
" would work.
E.Run runForBreak = new E.Run();
E.Text textForBreak = new E.Text() { Space = SpaceProcessingModeValues.Preserve };
textForBreak.Text = "\n";
runForBreak.Append(textForBreak);
sharedStringItem.Append(runForBreak);
"\n" works fine. If the input is coming from a multi-line textbox, the new line characters will be "\r\n", if this is replaced with "\n", it will work.
You can use Chr(13). Then just wrap the whole thing in Chr(34). Chr(34) is double quotes.
Actually, it is really simple.
You may edit an xml version of excel. Edit a cell to give it new line between your text, then save it. Later you may open the file in editor, then you will see a new line is represented by
Have a try....