Why am I getting an “invalid or unitialized Zip object” error when trying to read excel file via PHP?

后端 未结 2 1820
情深已故
情深已故 2021-02-04 11:28

I would like to find out how to read an excel file using via PHP. My specific use case is using PHPExcel from within Yii.

I have followed numerous tu

相关标签:
2条回答
  • 2021-02-04 12:18

    It looks like you set PHPExcel to explicitly use the 2007 format, but you're trying to open an XLS file. While I'm not 100% sure, I'm going to guess the zip error is because it's trying to unzip the XLS file, and that's going to fail as it's not zipped.

    The php zip extension appears to be working, as the error is from the extension - Invalid or unitialized Zip object. My guess is that you're getting an invalid Zip object since you're not dealing with a zip file.

    If you're trying to open an XLS file, you probably want:

    $objReader = PHPExcel_IOFactory::createReader('Excel5');
    

    Alternatively, you could remove the explicit mode, and just rely upon the automatic file type resolution, e.g.:

    $objPHPExcel = PHPExcel_IOFactory::load("c:\cctv.xls");  // Remove the createReader line before this
    
    0 讨论(0)
  • 2021-02-04 12:22

    I had the same error message, but turned out to be an issue with file permissions (as suggested here: PHPExcel Warning: ZipArchive::getFromName(): Invalid or unitialized Zip object in).

    A quick chmod 644 on the Excel file fixed it.

    0 讨论(0)
提交回复
热议问题