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

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.

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

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

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?

Here is the example, i have excel viewer 2003.

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.

Hi,

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

Best regards,
Ulf

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 …




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");

Hi,

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

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

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);

Hi !

It’s ok !!

Thanks !