gpt4 book ai didi

How can I read an excel file inside of a zip using PhpSpreadsheet?(如何使用PhpSpreadSheet读取Zip中的Excel文件?)

转载 作者:bug小助手 更新时间:2023-10-28 10:08:00 32 4
gpt4 key购买 nike



if ($_SERVER["REQUEST_METHOD"] === "POST") {
if (isset($_FILES["file"]["tmp_name"]) && !empty($_FILES["file"]["tmp_name"])) {
$file = $_FILES["file"]["tmp_name"];
$file_name = $_FILES["file"]["name"];
$zip = new ZipArchive();

if ($zip->open($file) === TRUE) {

echo "the zip archive has been opened <br>";

$desiredFileName = "Week1_2019.xlsx";

if ($zip->locateName($desiredFileName) !== false) {

echo "the zip file has been located <br>";

$full_path = "zip://$file#$desiredFileName";

try {
$spreadsheet = IOFactory::load($full_path);
} catch (PhpOffice\PhpSpreadsheet\Reader\Exception $e) {
echo 'Error loading file: ' . $e->getMessage();
}
}
$zip->close();
}
}
}


I am trying to parse excel files within a zip file using PhpSpreadsheet. Currently this is my output:

我正在尝试使用PhpSpreadSheet解析压缩文件中的EXCEL文件。目前,这是我的输出:


the zip archive has been opened
the zip file has been located
Error loading file: File "zip://C:\xampp\tmp\php4229.tmp#Week1_2019.xlsx" does not exist.

I have also tried supplying the raw file name as a string i.e $desiredFileName which throws the same exception: Error loading file: File "Week1_2019.xlsx" does not exist.

我还尝试以字符串形式提供原始文件名,即$desiredFileName,它抛出相同的异常:加载文件时出错:文件“Week1_2019.xlsx”不存在。


$spreadsheet = IOFactory::load($desiredFileName);

更多回答

Try closing the zip before calling IOFactory::load().

在调用IOFactory::Load()之前尝试关闭压缩包。

优秀答案推荐
更多回答

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com