PHPOffice / PhpSpreadsheet

A pure PHP library for reading and writing spreadsheet files
https://phpspreadsheet.readthedocs.io
MIT License
13.31k stars 3.45k forks source link

Corrupted .xlsx file on centos 8. On Windows works fine #2480

Open windstep opened 2 years ago

windstep commented 2 years ago

This is:

- [x] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

Working xlsx file

What is the current behavior?

File is created, but corrupted. It reproduces only on server, running on centos 8, locally this code works fine

What are the steps to reproduce?

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

On a fresh laravel instance in file routes/web.php

<?php

$router->get('/test', function () {
        $spreadsheet = new PhpOffice\PhpSpreadsheet\Spreadsheet();
        $sheet = $spreadsheet->getActiveSheet();
        $sheet->fromArray([['123', '456']]);
        $writer = new PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
        $writer->save(storage_path('1.xlsx'));

        return response()->download(storage_path('1.xlsx'))->deleteFileAfterSend(true);
});

You may also copy this on basic .php file, but I didn't tested it that way.

Which versions of PhpSpreadsheet and PHP are affected?

We are using 1.20 version of phpspreadsheet, and php 7.2.34, running on centos 8 Generated file is below

1.xlsx .

MarkBaker commented 2 years ago

As always when a corrupted file is generated, open the file in a text editor, and look for any PHP messages in the file

windstep commented 2 years ago

There are no php messages there i've sent an example file

MarkBaker commented 2 years ago

I can see that the file has a corrupted zip header. Can you check the the version of maennchen/zipstream-php that's listed in your composer.lock file?

Note that we don't actively support PHP 7,2 any more from PHPSpreadsheet 1.20 onwards

windstep commented 2 years ago

In composer.lock I see 2.1.0

SXH0212 commented 2 years ago

I have this problem too, image The saved file is downloaded to windows 10, the EXCEL file cannot be opened thank you

itgenolife commented 1 year ago

i have the same issue in windows 11 and office 2021, but my file is builded with centos 7

MarkBaker commented 1 year ago

Without a lot more information, such as a copy of the file, I can't possibly guess!

MarkBaker commented 1 year ago

Try checking your logs for errors, or opening the file in a text editor and looking for human-readable messages there