When trying to get an Excel spreadsheet from php with phpexcel, strange characters are generated in the output if a constant definition (DEFINE (' var',' value') is added. My code
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="theFile.xls"');
header('Cache-Control: max-age=0');
require_once '../config.php';
include 'PHPExcel.php';
$excel = new PHPExcel();
$writer = PHPExcel_IOFactory::createWriter($excel, 'Excel5');
$excel->setActiveSheetIndex(0);
$excel->getActiveSheet()->SetCellValue('A1', 'Hello');
$excel->getActiveSheet()->SetCellValue('B2', 'world!');
$writer->save('php://output');
I don't understand the reason, since config. php is all it contains.
If I delete the config. php line, the excel file is generated correctly Does anyone know what this behavior is due to?
this code runs smoothly
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="theFile.xls"');
header('Cache-Control: max-age=0');
include 'PHPExcel.php';
$excel = new PHPExcel();
$writer = PHPExcel_IOFactory::createWriter($excel, 'Excel5');
$excel->setActiveSheetIndex(0);
$excel->getActiveSheet()->SetCellValue('A1', 'Hello');
$excel->getActiveSheet()->SetCellValue('B2', 'world!');
$writer->save('php://output');
config.php content
define('DB_HOST', 'myHost');
define('DB_USER', 'myUser');
define('DB_PASSWORD', 'myPass');
define('DB_DATABASE', 'myDB');