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);
        }

 

posted @ 2019-02-18 20:07  温柔的风  阅读(320)  评论(0编辑  收藏  举报