views:

201

answers:

2

I am using a Windows application and I export a datatable into an Excel sheet. It displays successfully. Now I want to have multiple lines in a single cell. How can I do this by using C#?

A: 

Take the lines you want and put them into an array, and then join them into a single string, split by the newline character:

String singleCell = String.Join("\n",lines)

and then drop that string into the cell.

daniel
+1  A: 

You can just use "\n" in the String

Excel.Range dataRange= (Excel.Range)excelWorksheet.get_Range("C4", "C4");
dataRange.Value2 = "This is the first line\n" +
        "This is the second line\n" +          
        thirdLineString;
LnDCobra
Thanks yar... Nice code
Suryakavitha