Passing new line symbol in variable

Topics: Developer Forum, User Forum
Dec 28, 2011 at 11:14 PM

Hello all,


I need to set value in a cell using a variable. The value is a string containing new line symbol (\n). This does not work for me. I have tried dozens of ways. When I write a string manually it works. If I do it via a variable it just writes whole string in one line into the cell with or without the quotes (depend which variant I am testing):  "\n2011-12-18\n2011-12-18"

Code looks like this:


// I retrieve a string from a cell
$cell_value=$objPHPExcel->getActiveSheet()->getCellByColumnAndRow(8, $row_counter)->getValue(); 
// I get rid of quotes from the retrieved string, add new line symbol, add new string and put that in quotes again 
$cell_value='"'.str_replace('"', '', $cell_value).'\n'.$row[absence_date_from].'"';
//I put the newly created string into the same cell
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(8, $row_counter, $cell_value);

Can anyone help? Spend 3 hours on that and nothing :( Or maybe you have a better way to do it?


Jan 2, 2012 at 11:01 AM

Basic PHP.... use "\n" rather than '\n'