Example 06largescale.php (Excel2007) with a newline (\n) in a cell does not work

Topics: User Forum
Nov 20, 2014 at 2:21 PM

When modifying the 06largescale example by replacing 'Lastname' with 'Hello\nWorld', the xslx (Excel 2007) file is not valid and cannot be open.

I use the last versoin 1.8.0.

Has someone encounter the same problem ?


Nov 23, 2014 at 3:36 PM
This should not cause the workbook to be invalid, though you should use double quotes (") rather than single quotes(') unless you want \n to be a literal \n rather than a new line character
Nov 23, 2014 at 7:25 PM
Thank you MarkBaker.
But the phpexcel's 06largescale example uses double quotes.

// Add data
for ($i = 2; $i <= 5000; $i++) {
$objPHPExcel->getActiveSheet()->setCellValue('A' . $i, "Hello\nWorld")
                              ->setCellValue('B' . $i, "LName $i")
                              ->setCellValue('C' . $i, "PhoneNo $i")
                              ->setCellValue('D' . $i, "FaxNo $i")
                              ->setCellValue('E' . $i, true);
Nov 23, 2014 at 9:24 PM
If that is the only change you've made, then the file shouldn't be invalid, there is nothing wrong with your code as posted
Nov 23, 2014 at 9:32 PM
Open the generated file in a text editor.

Look for leading/trailing whitespace characters, any BOM header, or any plaintext PHP error messages visible in the file body