Write a newline character "\n" in a cell (ALT+"Enter")

Aug 30, 2010 at 6:57 AM

Hello Have anyone have these problem?

When I try to use White a newline function:

the code is:

$test = ('\nNew Respon 1\nNew Respon 1\nNew Respon 1\nNew Respon 1');

$objPHPExcel->getActiveSheet()->getCell('A1')->setValue($test);

It cannot insert new line but when I try this:


$objPHPExcel->getActiveSheet()->getCell('A1')->setValue('\nNew Respon 1\nNew Respon 1\nNew Respon 1\nNew Respon 1');

 

It works, so is this setValue this function cannot insert new line when we place variable in there?

Thanks

Aug 30, 2010 at 10:17 AM

$test = ('\nNew Respon 1\nNew Respon 1\nNew Respon 1\nNew Respon 1');

 

What are the parenthesis for?

Aug 30, 2010 at 11:23 AM

as I have few string and I want to display in few line in same cell. but When I use sting it works, but if string in varialbe, it cannot works.

Aug 31, 2010 at 6:47 AM

I found the reason now, as I use singe quote for string, but these function should use double quote, I can successfully  display in few lines now.

Coordinator
Sep 1, 2010 at 12:18 PM

As you've identified, standard PHP behaviour applies when embedding \n in strings... use double quotes ("ABC\nDEF") and PHP will treat the \n as a new line; use single quotes ('ABC\nDEF') and it will be treated as a '\' character followed by an 'n' character

Jul 21, 2011 at 10:28 PM
Edited Jul 21, 2011 at 10:28 PM

This is a slightly old topic, but I have similar problem, so I figured I'd use it.

Inserting newline in cell basically doesn't work for me. I enter "ABC\nDEF" as a value and a generated excel file displays a square where a new line should be. I use xlsx writer, so I can extract the file, and I see that newline is saved as \n character, while it should be saved as \r\n.

Entering "ABC\r\nDEF" in PHPExcel doesn't work either -- still just \n is written into the file.

When I insert a newline in Excel, the sequence of \r\n is written.

Is this a bug in xlsx writer?

PHPExcel 1.7.6.

Aug 25, 2011 at 10:25 AM
trybowski wrote:

This is a slightly old topic, but I have similar problem, so I figured I'd use it.

Inserting newline in cell basically doesn't work for me. I enter "ABC\nDEF" as a value and a generated excel file displays a square where a new line should be. I use xlsx writer, so I can extract the file, and I see that newline is saved as \n character, while it should be saved as \r\n.

Entering "ABC\r\nDEF" in PHPExcel doesn't work either -- still just \n is written into the file.

When I insert a newline in Excel, the sequence of \r\n is written.

Is this a bug in xlsx writer?

PHPExcel 1.7.6.

Hi I can write a new line to cell using the \r or the \n using the excel2007 writer  but when I read the cell I am unable to detect the \r or \n. What do you use to see the \r or \n with reading a cell.