Enter new line in php excel

In PHPExcel, you can insert a new line in a cell using the setCellValue() method and passing the value as an array with the desired line breaks.

Here is an example:

$objPHPExcel->getActiveSheet()->setCellValue('A1', array(
    'This is the first line',
    'This is the second line',
    'This is the third line'
));

This will insert a new line in cell A1 with the specified text.

Alternatively, you can use the setFormula() method and pass a formula that inserts a new line, such as:

$objPHPExcel->getActiveSheet()->setFormula('A1={"This is the first line";"This is the second line";"This is the third line"}');

This will also insert a new line in cell A1 with the specified text.

Note that in both cases, the new line is inserted using the semicolon (;) character, which is the default separator for arrays in PHP.

If you want to insert a new line in a specific cell, you can use the setCellFormula() method and pass the cell reference and the formula, like this:

$objPHPExcel->getActiveSheet()->setCellFormula('A1={"This is the first line";"This is the second line";"This is the third line"}');

This will insert a new line in cell A1 with the specified text.

You can also use the getSheet()->getStyle()->getAlignment()->setWrapText(true) to enable wrap text in the cell, so the text will be wrapped to the next line.

Please note that the above examples are for PHPExcel 1.x, if you are using PHPExcel 2.x, you should use setCellValueExplicit() instead of setCellValue() and setFormula().