Problem, array output to setCellValuebyColandRow linebreak problem

Topics: User Forum
Jan 13, 2011 at 2:14 PM
Edited Jan 13, 2011 at 2:14 PM

Hello everybody,

i have a textarea. This textare is sendet by a request to my PHPExcel writer. before i create the Excel file i split the textare content via explode.

The array values of the explode, iam using to set the Values in specific cells. My Problem is, the content is including line breaks (\n) but in my excel the line break are not show he is just

outputing the string like        test\ntest, but he is not interpreting the \n as a linebreak in excel.

When i writing not dynamically the values into some cells like this,   setCellValueByColumnAndRow(1,2,"test\ntest") its working.

So i dont know what to do further.

PS. I have included AdvancedValueBinder which should automaticaly interprete the \n as linebreak

require_once "../../plugins/excelreader/Classes/PHPExcel/Cell/AdvancedValueBinder.php";

PHPExcel_Cell::setValueBinder( new PHPExcel_Cell_AdvancedValueBinder() );

please help

thanks

harrison

Coordinator
Jan 13, 2011 at 9:30 PM

The behaviour that you describe suggest that the string contains the two characters '\' and 'n' rather than the new line character ("\n"). It suggests to me that there is some problem perhaps when you are splitting the textarea with explode. How are you doing this?

Jan 13, 2011 at 11:10 PM

hi Mark,

this is how iam splitting the textarea post.

$replace_br = str_replace('<br>','\n', $_POST['content_excel']);

$replace_end = str_replace('&nbsp;','', $replace_br);
           
$req_array_excel = explode('$tr$',$replace_end);

..

as you can see iam exploding the textarea values not just once. Its just a little code snippet

...

list($anz_eintra_prev, $row_prev, $column_prev,$inhalt) = explode('_tr_', $eintraege[$s-1]);  

...

$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($previsouscolumn,$row_start_entries,$inhalt);

as you can see iam creating a list and then putting it in setCellValueByColumnAndRow.

butI dont know where the problem should be.

 

--> the same problem i had with a normal array. You can see it here

array(3 =>"8:00\n-\n9:30",4=>"9:40\n-\n11:15",5=>"11:30\n-\n13:00",6=>"Mittagspause",7=>"14:00\n-\n15:30",8=>"15:45\n-\n17:15",9=>"17:30\n-\n19:00");

but i solved the problem by changing normal  single ' character by a double " character in the array. But i dont know why the problem is caused by that. Because normal ' character is the same like double " in php.

harrison

 

Coordinator
Jan 13, 2011 at 11:17 PM
Edited Jan 13, 2011 at 11:18 PM

Standard PHP string parsing rules... '\n' is two characters, "\n" is a new line. normal ' character is NOT the same as double " in php.

and watch out for '<br />' as well

 

 

Jan 14, 2011 at 6:20 PM

thanks now it works, i forgot about single character and double characters :) hehe, but now know what about the single and double one.

Thanks