Inserting text with multiple lines in a cell/column

Hi,
I am trying to insert a piece of text like -

This is line 1 of row1,
This is line 2 of row1

inside a single cell/column. How do i define a linebreak or rather insert the second string of text in a new row which is then merged with the previous one ?

regards,
Jaideep.

Please try:

Workbook wb = new Workbook();

Worksheet sheet = wb.Worksheets[0];

Cell cell = sheet.Cells["A1"];

cell.PutValue("This is line 1 of row1,\nThis is line 2 of row1");

cell.Style.IsTextWrapped = true;

sheet.AutoFitRow(0);

Laurence,

thanks for the prompt reply.



I tried using the steps you mentioned, but that doesn’t really work for me.

For one - the “\n” does not act as a line break in the string, instead
it is treated as another character and i get the output as “This is
line 1 of row1,\n This is line 2 of row1”.

Could you look into this please?

regards,
Jaideep.

Hi,

Thanks for considering Aspose.

Well, I tried the following Laurence code using Aspose.Cells 4.1.2.16 (you may download @: <A href="</FONT></A>) and it works fine and the output file (attached) is<FONT color=#000000> ok:</FONT></P> <P><FONT color=#000000>Workbook wb = </FONT><FONT color=#000000>new</FONT><FONT color=#000000> Workbook();</FONT></P> <P><FONT color=#000000>Worksheet sheet = wb.Worksheets[0];</FONT></P> <P><FONT color=#000000>Cell cell = sheet.Cells["A1"];

cell.PutValue("This is line 1 of row1,\nThis is line 2 of row1");

cell.Style.IsTextWrapped = true;

sheet.Cells.SetRowHeight(0,28);

sheet.Cells.SetColumnWidth(0,22);

//sheet.AutoFitRow(0);

wb.Save("d:\\test\\textwrap.xls");

Which version of Aspose.Cells you are using?

Thank you.

Thanks for the response amjad.

I am using version 4.1.2.9, and it doesn’t support cell features like setRowHeight etc.

Also, is it possible to not specify the rowHeight and columnwidth - but instead have the column width set to the point where the new line character is first read ?

regards
Jaideep.

could you also please attach the latest build ?

regards
Jaideep.

Hi,

Well, I tried uploading the recent fix but could not.... Could you try downloading at: <A href="</FONT></A></P> <P></FONT><FONT color=#0000ff size=3>Also, is it possible to not specify the rowHeight and columnwidth - but instead have the column width set to the point where the new line character is first read ?<BR></FONT></P> <P><FONT color=#000000>Well, you have to set either row/column height and width related to your data's size and to set to the point where the new line character is first read or use Worksheet.AutoFitRow() method to fit your data in more general way.</FONT></P> <P><FONT color=#000000>Thank you.</FONT></P> <P><FONT color=#000000> </P></FONT>

thanks amjad,
I did download the latest build from the link you provided.

but i still get the same issue, where the “\n” is read as a literal character and not as a carriage return or line break.


Are you using VB to develop your program? If yes, please change "\n" to chr(10)

cell.PutValue("line1"+chr(10)+"line2")

If you use C#, could you please post your output file here?

Laurence,
thanks for the reply.
I am using vb.net to code, and this option worked fine for me.

regards,
Jaideep.