Phpspreadsheet - не могу скачать файл xlsx - PullRequest
0 голосов
/ 02 ноября 2019

Я использую macOS и пробую phpspreadsheet. Если я даю разрешение на папку с проектом, я могу сохранить файл xlsx, и все в порядке. Но если я хочу скачать его, xlsx не работает, файл говорит мне, что расширение не совпадает с контентом. Если я переименую xlsx в xls в xls, это:

Warning:  ZipArchive::close(): Failure to create temporary file: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/EXPORT_TEST/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xlsx.php on line 409
Fatal error:  Uncaught PhpOffice\PhpSpreadsheet\Writer\Exception: Could not close zip file php://stdout. in /Applications/XAMPP/xamppfiles/htdocs/EXPORT_TEST/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xlsx.php:410
Stack trace:
#0 /Applications/XAMPP/xamppfiles/htdocs/EXPORT_TEST/test_export_2.php(25): PhpOffice\PhpSpreadsheet\Writer\Xlsx->save('php://stdout')
#1 {main}
thrown in /Applications/XAMPP/xamppfiles/htdocs/EXPORT_TEST/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xlsx.php on line 410

Я даю разрешение на все подпапки в XAMPP, но та же проблема.

    <?php
    //call the autoload
    require 'vendor/autoload.php';
    //load phpspreadsheet class using namespaces
    use PhpOffice\PhpSpreadsheet\Spreadsheet;
    //call iofactory instead of xlsx writer
    use PhpOffice\PhpSpreadsheet\IOFactory;

    //make a new spreadsheet object
    $spreadsheet = new Spreadsheet();
    //get current active sheet (first sheet)
    $sheet = $spreadsheet->getActiveSheet();
    //set the value of cell a1 to "Hello World!"
    $sheet->setCellValue('A1', 'Hello World !');

    //set the header first, so the result will be treated as an xlsx file.
    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');

    //make it an attachment so we can define filename
    header('Content-Disposition: attachment;filename="result.xlsx"');

    //create IOFactory object
    $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
    //save into php output
    $writer->save('php://stdout');

Можете ли вы дать мне несколько советов, чтонеправильно?

...