1.8.0"
我的 Web 应用程序的目标是有一个用户单击的按钮。
后面的代码将开始扫描主 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 );
}
}