PHPOffice / PhpSpreadsheet

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

Error exporting excel,zipstream usage error #4146

Open sonkwl opened 3 weeks ago

sonkwl commented 3 weeks ago

My code.

$write=IOFactory::createWriter($spreadsheet,"Xlsx");
$write->save("php://output");

Specific errors are reported as follows

<br />
<b>Fatal error</b>:  Uncaught TypeError: ZipStream\ZipStream::__construct(): Argument #1 ($operationMode) must be of type ZipStream\OperationMode, null given, called in /usr/share/nginx/html/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/ZipStream2.php on line 19 and defined in /usr/share/nginx/html/vendor/maennchen/zipstream-php/src/ZipStream.php:207
Stack trace:
#0 /usr/share/nginx/html/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/ZipStream2.php(19): ZipStream\ZipStream-&gt;__construct()
#1 /usr/share/nginx/html/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/ZipStream0.php(15): 

Locating Error Codes

phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/ZipStream2.php on line 19

19 return new ZipStream(null, $options);

The error appears to be due to incorrect use of the constructor。

How I handle it.

phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/ZipStream0.php

public static function newZipStream($fileHandle): ZipStream
    {
        //source code
        //return class_exists(Archive::class) ? ZipStream2::newZipStream($fileHandle) :ZipStream3::newZipStream($fileHandle);
        return class_exists(Archive::class) ? ZipStream3::newZipStream($fileHandle) :ZipStream3::newZipStream($fileHandle);
    }

compulsory use “ZipStream3::newZipStream”.

version information

Originally posted by @sonkwl in https://github.com/PHPOffice/PhpSpreadsheet/issues/4145#issuecomment-2306061242

oleibman commented 3 weeks ago

You have added comments to issue #4145 that clearly should have been added to this one. Please delete the comments there and re-add them here.

oleibman commented 3 weeks ago

As for your issue, you have a problem with Composer, possibly related to how it caches its information. See https://github.com/PHPOffice/PhpSpreadsheet/issues/3615#issuecomment-1595846986 for steps to correct it.

sonkwl commented 3 weeks ago

Thank you for your reply. My project handles network isolation status and cannot be updated directly using composer. My guess would be the zipstream version issue. I see #3615 issuse is open.Are there any plans to fix this issuse?Or add a new version error alert.

oleibman commented 3 weeks ago

The issue is open only so that the fix to the Composer problem is easily available to those experiencing the problem. There is no problem to fix in PhpSpreadsheet in a properly configured environment.