Search code examples
phpphpexcelphpoffice

PhpExcel new line in cell


What I do:

  1. query data from db
  2. explode data and insert \n
  3. prepare array
  4. open tamplate
  5. insert array into tamplate
  6. try to replace \n with new line

How can I found \n and insert new line? For example I have in A1 next text "One\nTwo". I read text from A1

$ltr='A1';
$vle=$spreadsheet->getActiveSheet()->getCell($ltr);

After this I try to insert text in A1 again in A1 and replace \n with new line in one cell

$spreadsheet->getActiveSheet()->getCell($ltr)->setValue("${vle}");
$spreadsheet->getActiveSheet()->getStyle($ltr)->getAlignment()->setWrapText(true);

But it does not work for my.

For example: enter image description here

So, if I open tamplate with text I can't replace \n in cells. What can I do?

Upd. I try use char(10) and insert formula (for example) ="hello"&char(10)&"world" But inserted only ="hello"&char(10)


Solution

  • When I explode/implode str and insert \n I use ''. Need use ""

    implode("\n", $array);