gistfile1.txt public function importFromExcel($excel_url){ //Loader::import('phpexcel.PHPExcel'); Loader::import('phpexcel.PHPExcel.IOFactory'); // $phpExcel = new \PHPExcel(); $fileExt = getExt($excel_url); if ($fileExt == 'xls') { $reader
public function importFromExcel($excel_url) { //Loader::import('phpexcel.PHPExcel'); Loader::import('phpexcel.PHPExcel.IOFactory'); // $phpExcel = new \PHPExcel(); $fileExt = getExt($excel_url); if ($fileExt == 'xls') { $reader = \PHPExcel_IOFactory::createReader('Excel5'); } else { $reader = \PHPExcel_IOFactory::createReader('Excel2007'); } //$reader = \PHPExcel_IOFactory::createReader('Excel2007'); //$reader = \PHPExcel_IOFactory::createReader('Excel5'); $allSheets = $reader->load('/www/FenFa/public'.$excel_url); $excel_arr = $allSheets->getSheet(0)->toArray(); array_shift($excel_arr); $data = []; foreach ($excel_arr as $k=>$v) { if ($v[1]) { $data[$k]['data_time'] = strtotime(str_replace('.', '-', $v[0])); $data[$k]['cooperation_id'] = $v[1]; $data[$k]['settlement_price'] = $v[2]; $data[$k]['settlement_ratio'] = $v[3]; $data[$k]['settlement_num'] = $v[4]; } } foreach ($data as $v) { if ($v['cooperation_id']) { Db::name('data')->insert($v); } } }