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

Topics: User Forum
Nov 20, 2014 at 1:21 PM
Hello,

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 ?

Thanks.

Stephane
Coordinator
Nov 23, 2014 at 2: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 6: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);
}
Coordinator
Nov 23, 2014 at 8: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
Coordinator
Nov 23, 2014 at 8: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