[英]How to import excel data into database using PHP excel library
我正在尝试使用 PHP excel 库将 excel 数据导入数据库。它适用于少量数据。对于大数据(30000 行)它不工作。
这是我的代码
$fileName = $_FILES["production"]["tmp_name"];
$objPHPExcel = PHPExcel_IOFactory::load($fileName);
$phpspreadsheet = $objPHPExcel->getSheet(0);
$total_data = $phpspreadsheet->getHighestRow();
//echo $chunkSize;
// exit;
$highest_column = $phpspreadsheet->getHighestColumn();
for ($row = 2 ; $row <= $total_data; $row++) {
$productionDataAll = $phpspreadsheet-> rangeToArray ('A' . $row . ':' . $highest_column . $row, NULL, TRUE, FALSE);
$line=htmlentities($productionDataAll[0][0]);
$workedorder=htmlentities($productionDataAll[0][1]);
$modelnumber=htmlentities($productionDataAll[0][2]);
$revision=htmlentities($productionDataAll[0][3]);
if(!empty($productionDataAll[0][4])){
$serialnumber=htmlentities($productionDataAll[0][4]);
}
else{
$serialnumber='';
}
$lpn=htmlentities($productionDataAll[0][5]);
$shift=htmlentities($productionDataAll[0][6]);
$datecreated=htmlentities($productionDataAll[0][7]);
$datecompleted=htmlentities($productionDataAll[0][8]);
$repairflag=htmlentities($productionDataAll[0][9]);
$date=date("Y-m-d", strtotime( '-1 days' ) );
$skeydate=date("Ymd", strtotime( '-1 days' ) );
$skey=$skeydate.$line;
$importproduction=importproduction($mysql_connectionLinkLocal,$line,$workedorder,$modelnumber,$revision,$serialnumber,$lpn,$shift,$repairflag,$date,$skey,$datecreated,$datecompleted); // insert function
}
上面的代码是一个一个地读取工作表数据并插入到数据库中。 如何按 100(块)读取工作表数据? 如何减少加载时间?我的页面无响应
试试https://github.com/aVadim483/fast-excel-reader
它可以非常快速地读取 excel 数据,并且使用最少的 memory (但仅限 XLSX 格式)。 在演示文件夹中有读取 100K 电子表格的示例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.