How to set String value to cell when the String contains \n


#1

Hi again,

I want to set the String “… \n …” to a cell, but the \n is unknown by Excel and it writes a square.

Best regards.


#2

What happens if you replace “\n” with “\r”?


#3

It writes a square too, and for the string \r\n i have two squares…


#4

Could you manually create an Excel file with \n and post it here? I will check it ASAP.

By the way, what's the language version of your MS Excel?


#5

Here is the example, i have excel viewer 2003.


#6

1. Do you use Aspose.Cells for Java to create this file? If it's created with Aspose.Cells for Java, could you manually create an Excle file which includes new lines but don't show this square symbol?

2. Does this file show square in your machine? I can see it in MS Excel without any problem.


#7

Hi,

You can use \012 instead of \n and Excel will handle it correctly.

Best regards,
Ulf


#8

Hi,

Laurence : 1.Yes, i create it with Aspose.Cells for Java, here is a file create manually (with a new line without square).
2. Yes, i see a square … (in the file created with aspose)
uleks : i try it and i always have the square …





#9

Hi,

The attached file is created with the following codes.It works ok.

Cells cells = worksheet.getCells();
Cell cell = cells.getCell("A1");
cell.setValue("Hello\nWorld");
cell = cells.getCell("A2");
cell.setValue("Hello\012World");


#10

Hi,

The Attached photo showes the screen when the created file is opened in our MS Excel .


#11

I have this result with your file … i don’t understand …!


#12

Hi,

We test the file with Excel Viewer .The file doesn't show square.You should set the text wrapped is true because the Viewer will not change the file.Please try the following codes:

Cells cells = worksheet.getCells();
Cell cell = cells.getCell("A1");
cell.setValue("Hello\nWorld!");
Style style = cell.getStyle();
style.setTextWrapped(true);
cell.setStyle(style);


#13

Hi !

It’s ok !!

Thanks !