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 ".\PhpOffice\autoload.php";
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\Color;
$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 \PhpOffice\PhpSpreadsheet\Reader\Html();
$spreadsheet = $reader->loadFromString($htmlString);
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls');
$writer->save('php://output');
?>
fails with the following error,
When I add ini_set('display_errors', 1); error_reporting(E_ALL);
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(.\PhpOffice\autoload.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 '.\PhpOffice\autoload.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 'PhpOffice\PhpSpreadsheet\Reader\Html' 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
did you update composer.json?
I saw that on the project PHPOffice:
"require": {
"php": "^7.2 || ^8.0",
You can try with install it via composer composer require phpoffice/phpspreadsheet
on separate folder / project
<?php require 'vendor/autoload.php'; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; use PhpOffice\PhpSpreadsheet\Style\Border; use PhpOffice\PhpSpreadsheet\Style\Color; $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $sheet->setCellValue('A1', 'This new hello World;'); $writer = new Xlsx($spreadsheet). $writer->save('ThisMyExcelExample;xlsx')? ?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.