Home >Backend Development >PHP Tutorial >用phpExcelReader不能导入大量数据,该怎么解决

用phpExcelReader不能导入大量数据,该怎么解决

ringa_lee
ringa_leeOriginal
2018-05-14 13:33:312437browse

用phpExcelReader不能导入大量数据
我在网上找了个例子,可以通过phpexcel将excel文件导入到数据库中,但是数据一旦超过122条,例如一个excel文件中有123条数据就无法导入。我讲代码贴出来,大家看看:

require_once '../phpExcelReader/Excel/reader.php';
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('GB2312');
$data->read('../lfx.xls');
}

for ($i = 1; $i <= $data->sheets[0][&#39;numRows&#39;]; $i++) 
{

for ($j = 1; $j <= $data->sheets[0][&#39;numCols&#39;]; $j++) 
{

echo $data->sheets[0][&#39;cells&#39;][$i][$j];
}
}

以上代码在excel文件小于123条时就可以打印出所有记录在网页上,但是大于等于123条时就是空白,而我需要导入一个5000条以上的数据,苦恼中。

附上phpExcelReader以及我的excel
感谢各位了!

------解决方案--------------------

PHP code
/* * PHPExcel.V1.7.6版本 [读取示例] */
include &#39;PHPExcel/IOFactory.php&#39;;
$filename = "d:/test.xls";
$readType = PHPExcel_IOFactory::identify($filename);  //在不知道文档类型的情况下获取
$excelReader = PHPExcel_IOFactory::createReader($readType);
$PHPExcelObj = $excelReader->load($filename);
$currentSheet = $PHPExcelObj->getSheet(0);            //选取第一张表单(Sheet1)为当前操作的表单
$excelRows = $currentSheet->getHighestRow();          //获取最大行
$excelColumn = $currentSheet->getHighestColumn();     //获取最大列
foreach(range(1,$excelRows) as $row){    
$line = &#39;<p>&#39;;    
foreach(range(&#39;A&#39;,$excelColumn) as $column){        
$line .= $currentSheet->getCell($column.$row)->getValue().",";    
}    
$line .= &#39;</p>&#39;;    
echo $line;}

------解决方案--------------------
探讨
我在网上找了个例子,可以通过phpexcel将excel文件导入到数据库中,但是数据一旦超过122条,例如一个excel文件中有123条数据就无法导入。我讲代码贴出来,大家看看:

require_once &#39;../phpExcelReader/Excel/reader.php&#39;;
$data = new Spreadsheet_Excel_Reader();
$data->setOutput……


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn