php 微擎 导入excel记录
时间:2024-4-30 10:59 作者:杨佳乐 分类: PHP
load()->library('phpexcel/PHPExcel');
load()->library('phpexcel/PHPExcel/IOFactory');
load()->library('phpexcel/PHPExcel/Reader/Excel5');
if (checksubmit('submit')){
load()->func('file');
if($_FILES['excel']['type']=="application/octet-stream"){
//文件上传
if (!file_move($_FILES['excel']['tmp_name'], ATTACHMENT_ROOT . '/leexcel/'.TIMESTAMP.'.xls')) {
message('文件上传失败,请尝试重新上传!','','error');
}else{
$objReader = PHPExcel_IOFactory::createReader('Excel5');
$objPHPExcel = PHPExcel_IOFactory::load(ATTACHMENT_ROOT . 'leexcel/'.TIMESTAMP.'.xls');
$sheet=$objPHPExcel->getSheet(0);//获取第一个工作表
$highestRow=$sheet->getHighestRow();//取得总行数
$highestColumn = $sheet- >getHighestColumn(); // 取得总列数 可以遍历行数的时候同时遍历列数
if($highestRow<2){
message('未发现导入数据!');
}
$succ=0;
for($j=2;$j<=$highestRow;$j++){
$kh=$objPHPExcel->getActiveSheet()->getCell("A".$j)->getValue();
$mm=$objPHPExcel->getActiveSheet()->getCell("B".$j)->getValue();
$je=$objPHPExcel->getActiveSheet()->getCell("C".$j)->getValue();
//获取日期处理$i=date('Y/m/d',PHPExcel_Shared_Date::ExcelToPHP($objPHPExcel->getActiveSheet()->getCell("I" . $j)->getValue()));
//echo $kh.'--'.$mm.'--'.$je."<br/>";
//插入数据
//查询卡号是否存在
$is_cz=pdo_get('tiger_newhu_le_km',array('kh'=>$kh));
if(empty($is_cz)){
//插入
if(!empty($kh) && !empty($mm) && !empty($je)){
$data=array(
'kh'=>$kh,
'mm'=>$mm,
'je'=>$je,
'createtime'=>TIMESTAMP
);
pdo_insert('tiger_newhu_le_km',$data);
$succ++;
}
}
}
message('导入完成,成功导入:'.$succ.'条','','success');
}
}else{
message('文件类型错误!','','error');
}
}
Uncaught exception 'PHPExcel_Exception' with message 'Unknown codepage: 10008' in 错误处理
在phpexcel/shared/codepage.php 增加
case 10008: return 'MAC'; break;