Commit 23d41d7b authored by zhuwei's avatar zhuwei

1

parent b53f8a89
......@@ -36,8 +36,8 @@ class ReadExcel extends Basic
$path = $_FILES['excel']['tmp_name'];
// $file = $_FILES['upload']['tmp_name'][0];
$data = $this->import_excel($path);
dump($data);
dump($path);
......@@ -47,33 +47,7 @@ class ReadExcel extends Basic
}
private function import_excel($file){
// 判断文件是什么格式
$type = pathinfo($file);
$type = strtolower($type["extension"]);
$type=$type==='csv' ? $type : 'Excel5';
ini_set('max_execution_time', '0');
Vendor('PHPExcel.PHPExcel');
// 判断使用哪种格式
$objReader = \PHPExcel_IOFactory::createReader($type);
$objPHPExcel = $objReader->load($file);
$sheet = $objPHPExcel->getSheet(0);
// 取得总行数
$highestRow = $sheet->getHighestRow();
// 取得总列数
$highestColumn = $sheet->getHighestColumn();
//循环读取excel文件,读取一条,插入一条
$data=array();
//从第一行开始读取数据
for($j=3;$j<=$highestRow;$j++){
//从A列读取数据
for($k='A';$k<=$highestColumn;$k++){
// 读取单元格
$data[$j][]=$objPHPExcel->getActiveSheet()->getCell("$k$j")->getValue();
}
}
return $data;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment