“ PHPSpreadSheet错误”您请求的工作表索引:-1超出范围。实际工作表数为0。

时间:2020-03-09 20:14:50

标签: php phpspreadsheet


我想将大约4000 .xls个文件导入MySQL。
为了读取.xls文件,我使用了PHPSpreadsheet
在大多数情况下,一切都很好,我编写的代码也行得通。
但是对于大约1000 .xls个文件,它不再起作用。
所有文件具有相同的结构,数据位于相同的单元格等中,但是内容不同。
当我尝试导入不起作用的文件之一时,它说: your requested sheet index: -1 is out of bounds. the actual number of sheets is 0.
我的代码:

foreach($filenames as $namen) {
    $inputFileName = "alles/".$namen;
    $inputFileType = IOFactory::identify($inputFileName);
    $reader =  new \PhpOffice\PhpSpreadsheet\Reader\Xls();
    $spreadsheet = $reader->load($inputFileName);
    $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
}

在上面的代码之前,我已经索引了文件夹alles/,所有文件名都在名为$filenames的数组变量中,然后创建了一个foreach循环。 修改1
我刚刚尝试了一些事情,但又遇到了一个新错误:
Notice: Trying to access array offset on value of type null in vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Calculation\Calculation.php on line 3647
我不知道这是calculation.php的代码还是我的代码中的问题。

0 个答案:

没有答案