PhpExcel新细胞系

What I do:

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

How can I found and insert new line? For example I have in A1 next text "One Two". 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 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 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)

If you're asking about this issue on the PHPspreadsheet github issues log then this is a problem with your understanding of PHP strings.

$dataArray = [
    ['2010', 'Q1', 'United
States', 790],
    ['2010', 'Q2', 'United States', 730],
    ['2010', 'Q3', 'United States', 860]
]

A ' ' in single quotes is treated as a literal ; a " " in double quotes is treated as a new line character. So either build your array using double quotes:

$dataArray = [
    ['2010', 'Q1', "United
States", 790],
    ['2010', 'Q2', "United States", 730],
    ['2010', 'Q3', "United States", 860]
]

or convert the literal to a new line using str_replace:

$modified = str_replace('
', "
", $original);

Using "char(10)" in excel formula. & = concantinate, and char(10) =

$textWithNewLine = '="hello"&char(10)&"world"';
$spreadsheet->getActiveSheet()->getCell($ltr)->setValue($textWithNewLine);

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

implode("
", $array);