大數(shù)據(jù)EXCEL 導(dǎo)入數(shù)據(jù)庫(kù)(50W+), 要怎么處理
? ? ? ?if (!empty($_FILES)) {
$config = array(
'exts' => array('xlsx','xls'),
'maxSize' => 134217728,
'rootPath' =>"./Public/",
'savePath' => 'Uploads/',
'subName' => array('date','Ymd'),
);
? ? ? ? ? ?$upload = new \Think\Upload($config);
? ? ? ? ? ?if (!$info = $upload->upload()) {
$this->error($upload->getError());
}
? ? ? ? ? ?vendor("PHPExcel.PHPExcel");
$file_name=$upload->rootPath.$info['photo']['savepath'].$info['photo']['savename'];
$extension = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));//判斷導(dǎo)入表格后綴格式
if ($extension == 'xlsx') {
$objReader =\PHPExcel_IOFactory::createReader('Excel2007');
$objPHPExcel =$objReader->load($file_name, $encode = 'utf-8');
} else if ($extension == 'xls'){
$objReader =\PHPExcel_IOFactory::createReader('Excel5');
$objPHPExcel =$objReader->load($file_name, $encode = 'utf-8');
}
$sheet =$objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow(); //取得總行數(shù)
$highestColumn =$sheet->getHighestColumn(); //取得總列數(shù)
? ? ? ? ? ? ? ? ? ? //sql拼接
? ? ? ? ? ? ? ? ? ? $sql = "INSERT INTO `song_sheet` (`song_no`, `song_name`, `singer_name`, `language`, `film_classification`, `dance_category`, `music_classification`, `epidemic_classification`, `picture_type`, `max_volume`, `song_count`, `backup_information`, `picture`, `retain`, `retain_date`) VALUES ";
for ($i = 2; $i <= $highestRow; $i++) {
? ? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? ? ? ? ? //拼接
? ? ? ? ? ? ? ? ? ? ? ? $sql .= "('".addslashes($objPHPExcel->getActiveSheet()->getCell("B" .$i)->getValue())."',"
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? . "'".addslashes($objPHPExcel->getActiveSheet()->getCell("C" .$i)->getValue())."',"
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? . "'".addslashes($objPHPExcel->getActiveSheet()->getCell("D" .$i)->getValue())."',"
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? . "'".addslashes($objPHPExcel->getActiveSheet()->getCell("E" .$i)->getValue())."',"
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? . "'".addslashes($objPHPExcel->getActiveSheet()->getCell("F" .$i)->getValue())."',"
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? . "'".addslashes($objPHPExcel->getActiveSheet()->getCell("G" .$i)->getValue())."',"
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? . "'".addslashes($objPHPExcel->getActiveSheet()->getCell("H" .$i)->getValue())."',"
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? . "'".addslashes($objPHPExcel->getActiveSheet()->getCell("I" .$i)->getValue())."',"
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? . "'".addslashes($objPHPExcel->getActiveSheet()->getCell("J" .$i)->getValue())."',"
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? . "'".addslashes($objPHPExcel->getActiveSheet()->getCell("K" .$i)->getValue())."',"
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? . "'".addslashes($objPHPExcel->getActiveSheet()->getCell("L" .$i)->getValue())."',"
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? . "'".addslashes($objPHPExcel->getActiveSheet()->getCell("M" .$i)->getValue())."',"
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? . "'".addslashes($objPHPExcel->getActiveSheet()->getCell("N" .$i)->getValue())."',"
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? . "'".$objPHPExcel->getActiveSheet()->getCell("O" .$i)->getValue()."',"
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? . "'".$objPHPExcel->getActiveSheet()->getCell("P" .$i)->getValue()."'"
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? . "),";
? ? ? ? ? ?}
? ? ? ? ? ? ? ? ? ? $sql ?= substr($sql,0,strlen($sql)-1);?
? ? ? ? ? ? ? ? ? ? $sql .=";";
? ? ? ? ? ? ? ? ? ? // print_r(array($sql));exit;
? ? ? ? ? ? ? ? ? ? $Model = new \Think\Model();
? ? ? ? ? ? ? ? ? ? $Model->execute($sql);
$this->success('導(dǎo)入成功!',U('Songsheet/index'));die;
? ? ? ?}else{
$this->success('請(qǐng)選擇上傳的文件!');die;
? ? ? ?}
2017-09-07
參照http://idcbgp.cn/video/8527