On updating my phpspreadsheet in composer to version v1.17.1 my code stopped working. I get a Warning "Cannot modify header information - headers already sent by" message instead. Why is phpspreadsheet changing the headers so I can't call the header command?
The below code convert html to xlsx then download the file. And it always worked until I updated. When I revert back to v1.16.0 the below code works.
$filename = '../tmp/' . $row['FileStoreID'] . '.' . $row['FileExtension'];
$todirectoryname = '../tmp/' . $row['FileStoreID'] . '/';
$filenameonly = $row['TransactionTypeName'] . ' - ' . $row['GroupingName'] . '.xlsx';
$tofilename = $todirectoryname . $filenameonly;
if (!is_dir($todirectoryname)) {
mkdir($todirectoryname);
}
file_put_contents($filename,$documentdata);
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Html');
$spreadsheet = $reader->load($filename);
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
$writer->save($tofilename);
header("Location: " . serverurl . '/tmp/' . $tofilename);
The "$writer->save($tofilename);" part of the code works because my temp file is created. But the "header("Location: " . serverurl . '/tmp/' . $tofilename);" do not work.
I have tried all the other suggestions to download phpspreadsheet files. But none of them worked.
See attached the screenshot of what the screen displays. It should not display anything it should download the created file.