Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从PHP解析Excel文件_Php_Excel - Fatal编程技术网

从PHP解析Excel文件

从PHP解析Excel文件,php,excel,Php,Excel,我有一个PHP函数来解析文件Excel,它读取所有行数,但不返回对象中的所有数据。 行数3247,但它只返回1023行 以下是解析函数: public function parseEquipement($filePath = null) { set_time_limit(0); $listEquipement = []; $count = 0; $chunkSize = 8192; $objR

我有一个PHP函数来解析文件Excel,它读取所有行数,但不返回对象中的所有数据。 行数3247,但它只返回1023行

以下是解析函数:

 public function parseEquipement($filePath = null) {    
        set_time_limit(0);
        $listEquipement = [];       
        $count = 0;
        $chunkSize = 8192;
        $objReader = PHPExcel_IOFactory::createReader(PHPExcel_IOFactory::identify($filePath));
        $spreadsheetInfo = $objReader->listWorksheetInfo($filePath);
        $chunkFilter = new \Floose\Parse\ChunkReadFilter();
        $objReader->setReadFilter($chunkFilter);
        $objReader->setReadDataOnly(true);
        $chunkFilter->setRows(0, 1);
        $objPHPExcel = $objReader->load($filePath);
        $totalRows = $spreadsheetInfo[0]['totalRows'];
        for ($startRow = 1; $startRow <= $totalRows; $startRow += $chunkSize) {
            $chunkFilter->setRows($startRow, $chunkSize);
            $objPHPExcel = $objReader->load($filePath);
            $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, null, true, false);
            $startIndex = ($startRow == 1) ? $startRow : $startRow - 1;         
            if (!empty($sheetData) && $startRow < $totalRows) {
                $dataToAnalyse = array_slice($sheetData, $startIndex, $chunkSize);  
                    if($dataToAnalyse[0][0]==NULL){         
                        break;
                }               
                for ($i = 0; $i < $chunkSize; $i++) {                       
                    if ($dataToAnalyse[$i]['0'] != NULL) {                      
                       $listEquipement[] = new Article($dataToAnalyse[$i]['0'], '', $dataToAnalyse[$i]['1']);                       
                        $count++;

                    }
                }
            } 

        //echo($totalRows); // is best
        //echo($count);  // is wrong
           //print_r($listEquipement);
            $objPHPExcel->disconnectWorksheets();
            unset($objPHPExcel, $sheetData);
        }   

        return $listEquipement;

        }
公共函数parseequipment($filePath=null){
设置时间限制(0);
$listquipement=[];
$count=0;
$chunkSize=8192;
$objReader=PHPExcel_IOFactory::createReader(PHPExcel_IOFactory::identify($filePath));
$spreadsheetInfo=$objReader->listWorksheetInfo($filePath);
$chunkFilter=new\flouse\Parse\ChunkReadFilter();
$objReader->setReadFilter($chunkFilter);
$objReader->setReadDataOnly(true);
$chunkFilter->setRows(0,1);
$objPHPExcel=$objReader->load($filePath);
$totalRows=$spreadsheetInfo[0]['totalRows'];
对于($startRow=1;$startRow setRows($startRow,$chunkSize);
$objPHPExcel=$objReader->load($filePath);
$sheetData=$objPHPExcel->getActiveSheet()->toArray(null、null、true、false);
$startIndex=($startRow==1)?$startRow:$startRow-1;
如果(!empty($sheetData)&&$startRow<$totalRows){
$dataToAnalyse=array\u slice($sheetData、$startIndex、$chunkSize);
如果($dataToAnalyse[0][0]==NULL){
打破
}               
对于($i=0;$i<$chunkSize;$i++){
如果($dataToAnalyse[$i]['0']!=NULL){
$listEquipement[]=新文章($dataToAnalyse[$i]['0'],'',$dataToAnalyse[$i]['1']);
$count++;
}
}
} 
//echo($totalRows);//是最好的
//echo($count);//错误
//打印($listquipement);
$objPHPExcel->disconnectWorksheets();
未设置($objPHPExcel,$sheetData);
}   
返回$listEquipement;
}
我通过以下方式更改了所有代码,但不起作用:

public function parseEquipment($filePath = null) {
    $objReader = PHPExcel_IOFactory::createReader(PHPExcel_IOFactory::identify($filePath));
    $objReader->setReadDataOnly(true);
    $objPHPExcel = $objReader->load($filePath);
    $sheet = $objPHPExcel->getSheet(0); 
    $highestRow = $sheet->getHighestRow();
    for ($row = 2; $row <= $highestRow; $row++){ 
        echo $sheet->getCellByColumnAndRow(3, $row)->getCalculatedValue();
        echo $sheet->getCellByColumnAndRow(4, $row)->getCalculatedValue();
        echo $sheet->getCellByColumnAndRow(2,$row)->getCalculatedValue();
        $listEquipement[] = new Article(
            $sheet->getCellByColumnAndRow(3, $row)->getCalculatedValue(),
            $sheet->getCellByColumnAndRow(4, $row)->getCalculatedValue(),
            $sheet->getCellByColumnAndRow(2, $row)->getCalculatedValue()
);

    }
}
公共函数解析设备($filePath=null){
$objReader=PHPExcel_IOFactory::createReader(PHPExcel_IOFactory::identify($filePath));
$objReader->setReadDataOnly(true);
$objPHPExcel=$objReader->load($filePath);
$sheet=$objPHPExcel->getSheet(0);
$highestRow=$sheet->getHighestRow();
对于($row=2;$row GetCellByColumnRow(3,$row)->getCalculatedValue();
echo$sheet->getCellByColumnRow(4,$row)->getCalculatedValue();
echo$sheet->getCellByColumnRow(2,$row)->getCalculatedValue();
$listquipement[]=新文章(
$sheet->GetCellByColumnRow(3,$row)->getCalculatedValue(),
$sheet->GetCellByColumnRow(4,$row)->getCalculatedValue(),
$sheet->getCellByColumnRow(2,$row)->getCalculatedValue()
);
}
}
当我运行我的代码时,它总是显示内存大小的错误,知道我的文件大小是81K,它同时显示行数

致命错误:允许的内存大小134217728字节已用尽(尝试分配54字节


有没有人可以指导和教我如何编写代码,或者你可以建议我使用另一种代码来解析Excel文件?

你可以检查代码是否存在内存泄漏,或者增加php脚本的内存。我如何检查代码是否存在内存泄漏。我尝试增加php脚本的内存,但实际上你可能需要检查代码是否存在内存泄漏或增加php脚本的内存。如何检查代码是否存在内存泄漏。我尝试增加php脚本的内存,但没有成功