Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to move text on new line in one cell.

Example, i have text :
abcdefg

i want :
abcd
efg


I tryed this.
C#
Range = mySheet.get_Range("C3", "C3");
range.Value2 = string.Concat(cell_value,"\n","/n")


not working

Excuse for bad English
Posted

1 solution

If you just want long text to wrap, set the wrap property:
C#
range.WrapText = True;


If you actually have content that you want to force to separate lines of the cell, try inserting a Char(10):
C#
range.Value2 = cell_value1 + (Char)10 + cell_value2;
 
Share this answer
 
Comments
[no name] 23-Apr-12 15:18pm    
range.WrapText = True; -- this code is work but string wrap on the end.
http://i42.tinypic.com/34nslfl.png
woopsydoozy 23-Apr-12 15:40pm    
OK, from your screenshot, it appears that you want to control where the break occurs. So you have to change the string you write to the Value property, inserting the correct character at the right places. I thought (char)10 should work--maybe you have to set WrapText along with it? Try this:
range.WrapText = True;
range.Value2 = cell_value.Replace(" ",(char)10); //assumes space is your delimiter
[no name] 23-Apr-12 16:01pm    
Error 2 Argument "2": the transformation of the type "char" in the "string" can not be
woopsydoozy 23-Apr-12 16:11pm    
OK, so cell_value.Replace(" ", ((char)10).ToString());

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900