【发布时间】:2021-08-19 22:58:17
【问题描述】:
1.8.0"
我的网络应用程序的目标是有一个用户点击的按钮。
后面的代码将开始扫描主 rdv 文件夹中的所有文件夹。
在 rdv 文件夹中,它包含三个名为 1000、1001、1002 的文件夹,其中包含 .xlsx 文件。
检索保存在每个文件夹中的最后一个文件 .xlsx
但之后就不行了。
致命错误:未捕获的 PHPExcel_Reader_Exception:无法打开 2.xlsx 供阅读!
所以我如何修复致命错误以及如何读取文件以继续代码,我想在 .xlsx 文件中获取 3 个值并插入到我的数据库中。
感谢您的宝贵时间。
include 'database.php';
require 'PHPExcel/Classes/PHPExcel.php';
require_once 'PHPExcel/Classes/PHPExcel/IOFactory.php';
// receives the 'someAction' value from the index page button.
if($_SERVER['REQUEST_METHOD'] == "POST" and isset($_POST['someAction']))
{
func();
}
function func()
{
//calcul the nomber of folder in folder rdv
$howManyFolder = count(glob('rdv/*', GLOB_ONLYDIR));
//retrieves the last file saved in each of the folders and insert into database
for ($i = 0; $i < $howManyFolder; $i++) {
$files = scandir("rdv/100$i", SCANDIR_SORT_DESCENDING);
echo "Recover all files in the folder 100" . $i . "<br>";
print_r($files ); echo "<br>";
echo "get the last file inserted in the folder at index 0 <br>";
$newest_file = $files[0]; print_r($newest_file); echo "<br>";
//load the file .xlsx (but the code bug here -_-)
$objExcel=PHPExcel_IOFactory::load($newest_file);
//get all value insinde the .xlsx file
$dossier = $objExcel->getActiveSheet()->getCell('A3')->getValue();
$facture = $objExcel->getActiveSheet()->getCell('B21')->getValue();
$date = $objExcel->getActiveSheet()->getCell('Q1')->getValue();
//call function to insert these values inside dataBase.
insertInto($dossier, $facture, $date );
}
}
【问题讨论】:
-
之后的错误信息还有吗?我期待它进一步解释为什么它无法打开它,例如“文件不存在”或类似的东西。
-
请编辑您的帖子并删除未使用的详细信息和文本以简化您的问题,并注意关注您的主要问题并详细解释它以帮助其他人回答您的问题。还可以从上面的代码 sn-p 中更多地解释您的问题/期望,以帮助您的问题易于理解。祝你好运????
-
您可以花点时间阅读这篇文章stackoverflow.com/help/how-to-ask,了解如何提问,也阅读这篇文章stackoverflow.com/help/minimal-reproducible-example,了解如何以最低要求提出一个好问题。
标签: php phpexcel phpexcelreader phpexcel-1.8.0