-2

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 );
    }
}       
4

1 回答 1

0

XML 解析器: https ://www.php.net/manual/en/book.xml.php

解析 XML 文档:https ://www.php.net/manual/en/function.xml-parse.php

<?PHP
$stream = fopen('large.xml', 'r');
$parser = xml_parser_create();
// set up the handlers here
while (($data = fread($stream, 16384))) {
    xml_parse($parser, $data); // parse the current chunk
}
xml_parse($parser, '', true); // finalize parsing
xml_parser_free($parser);
fclose($stream);
于 2021-08-20T03:48:46.820 回答