Yii1操作phpexcel
作者:互联网
Yii::import('application.vendors.phpexcel.*'); Yii::import('application.vendors.phpexcel.PHPExcel.*'); $objPHPExcel = new PHPExcel(); $objPHPExcel->getActiveSheet()->getProtection()->setSheet(false); $file = dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/ueditor1_2_5/keyword.xlsx'; $obj = PHPExcel_IOFactory::load($file); $sheet = $obj->getSheet(0); $hight = $sheet->getHighestRow(); $column = $sheet->getHighestColumn(); $column=PHPExcel_Cell::columnIndexFromString($column); $a=PHPExcel_Cell::stringFromColumnIndex(0); $b=$sheet->getCell($a.'1')->getValue(); $array=[]; for($i=0; $i<$column;$i++ ){ $numberName=PHPExcel_Cell::stringFromColumnIndex($i).'1'; $keyName=$sheet->getCell($numberName)->getValue(); array_push($array, $keyName); } $price=[]; for ($i=2 ;$i<$hight;$i++){ for($j=0;$j<$column;$j++){ $numberName=PHPExcel_Cell::stringFromColumnIndex($j).$i; $keyName=$sheet->getCell($numberName)->getValue(); $row[$array[$j]]=$keyName; } $price[]=$row; } foreach ($price as $v) { $sql = 'update t_knowledgenew set keywords = :keywords where id = :id'; $params[':keywords']=$v['keyword']; $params[':id']=$v['id']; $command = Yii::app ()->db->createCommand ($sql)->bindValues($params); $command->execute(); usleep(50000); }
标签:sheet,Yii,PHPExcel,Yii1,phpexcel,array,dirname,id,操作 来源: https://blog.51cto.com/u_15230485/2821224