I have tested this on 7.2 and it’s working. When I move this code to 7.3 it’s not working. I installed PHPSpreadsheet without using composer
<?php
namespace PhpOffice;
include ".PhpOfficeautoload.php";
use PhpOfficePhpSpreadsheetSpreadsheet;
use PhpOfficePhpSpreadsheetWriterXlsx;
use PhpOfficePhpSpreadsheetStyleBorder;
use PhpOfficePhpSpreadsheetStyleColor;
$htmlString = "<p>hello</p>";
$fileName = "myExcel";
$CntDisposition = "Content-Disposition: attachment;filename=";
$CntDisposition = $CntDisposition . $fileName . ".xls";
header($CntDisposition);
header('Cache-Control: max-age=0');
$reader = new PhpOfficePhpSpreadsheetReaderHtml();
$spreadsheet = $reader->loadFromString($htmlString);
$writer = PhpOfficePhpSpreadsheetIOFactory::createWriter($spreadsheet, 'Xls');
$writer->save('php://output');
?>
fails with the following error,
When I add ini_set('display_errors', 1); error_reporting(E_ALL);
befor the namespace it failed with 500. but when I add this below the namespace line the file got downloaded. But with followin stacktrack on the file,
<br />
<b>Warning</b>: include(.PhpOfficeautoload.php): failed to open stream: No such file or directory in <b>/home/u527331572/domains/thestory.host/public_html/adminPanel/adminPages/excel.php</b> on line <b>8</b><br />
<br />
<b>Warning</b>: include(): Failed opening '.PhpOfficeautoload.php' for inclusion (include_path='.:/opt/alt/php73/usr/share/pear') in <b>/home/u527331572/domains/thestory.host/public_html/adminPanel/adminPages/excel.php</b> on line <b>8</b><br />
<br />
<b>Fatal error</b>: Uncaught Error: Class 'PhpOfficePhpSpreadsheetReaderHtml' not found in /home/u527331572/domains/thestory.host/public_html/adminPanel/adminPages/excel.php:20
Stack trace:
#0 {main}
thrown in <b>/home/u527331572/domains/thestory.host/public_html/adminPanel/adminPages/excel.php</b> on line <b>20</b><br />
The mentioned files are available at the mentioned places though
2
Answers
did you update composer.json ?
I saw that on the project PHPOffice:
You can try with install it via composer
composer require phpoffice/phpspreadsheet
on separate folder / project