329s

329s

这家伙有点懒,还没写个性签名!

  • 财富值

    50

  • 威望值

    0

  • 总积分

    110

个人信息

  • 回复了 的回答

    好问题

    说错了,我使用的是使用布局的

  • 回复了 的回答

    好问题

    renderPartialrender 这两个区别,但是我调用的是 renderPartial 这个,应该在框架内的,结果跳出框架了

  • 回复了 的回复

    ` /**

     * actionExecl 导出Execl
     */
    public function actionExecl($execlString)
    {
        $sql = yii::$app->security->decryptByPassword(base64_decode($execlString), Yii::$app->params['cryptSecretKey']);
    
        if(!$sql){
            Yii::$app->session->setFlash('error', '参数错误');
            return $this->redirect(['/search-record/index']);
        }
    
        $result = Yii::$app->db->createCommand($sql)->queryAll();
    
        if(!$result){
            Yii::$app->session->setFlash('error', '没有导出的数据');
            return $this->redirect(['/search-record/index']);
        }
    
        $objectPHPExcel = new \PHPExcel();
        $objectPHPExcel->setActiveSheetIndex(0);
        //报表头的输出
        $objectPHPExcel->getActiveSheet()->mergeCells('A1:J1');
        $objectPHPExcel->getActiveSheet()->setCellValue('A1','搜索统计');
        $objectPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getFont()->setSize(24);
        $objectPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
    
        //表格头的输出
        $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('A2','序号');
        $objectPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(25);
    
        $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('B2','关键词');
        $objectPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
    
        $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('C2','搜索频次');
        $objectPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(15);
    
        $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('D2','更新时间');
        $objectPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
    
        $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('E2','是否为热搜');
        $objectPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(15);
    
        $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('F2','关键词来源');
        $objectPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(20);
        //设置居中
        $objectPHPExcel->getActiveSheet()->getStyle('A2:J2')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objectPHPExcel->getActiveSheet()->getStyle('A:J')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
    
        $i=3;
    
        $sourceLabel = SearchRecord::$sourceLabel;
    
        foreach($result as $key=>$vo)
        {
            $objectPHPExcel->getActiveSheet()->setCellValue('A'.$i ,$key+1);
            $objectPHPExcel->getActiveSheet()->setCellValue('B'.$i ,$vo['name']);
            $objectPHPExcel->getActiveSheet()->setCellValue('C'.$i ,$vo['times']);
            $objectPHPExcel->getActiveSheet()->setCellValue('D'.$i ,$vo['updateTime']);
            $objectPHPExcel->getActiveSheet()->setCellValue('E'.$i ,$vo['isHot']?'是':'否');
            $objectPHPExcel->getActiveSheet()->setCellValue('F'.$i ,$sourceLabel[$vo['source']]??'');
            $i++;
        }
    
        $objectPHPExcel->getActiveSheet()->getPageSetup()->setHorizontalCentered(true);
        $objectPHPExcel->getActiveSheet()->getPageSetup()->setVerticalCentered(false);
        ob_end_clean();
        ob_start();
        header('Content-Type : application/vnd.ms-excel');
        header('Content-Disposition:attachment;filename="'.'搜索统计-'.date("Y年m月j日").'.xls"');
        $objWriter= \PHPExcel_IOFactory::createWriter($objectPHPExcel,'Excel2007');
        $objWriter->save('php://output');
    }`
    

    谢谢已经解决了,应该是路径问题,虽然不知道之前为什么没有报错,http://blog.csdn.net/u014273681/article/details/78893911

  • 回复了 的回复

    给你个创建excel的方法, 肯定好用

    public static function createExcel(PHPExcel $objPHPExcel = NULL,$fileName = 'example.xlsx',$download = false)
    {
        $objPHPExcel = $objPHPExcel ? $objPHPExcel : new PHPExcel;
        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
        if($download){
            $fileName = basename($fileName);
            $fileName = iconv("utf-8", "gb2312", $fileName);
            header('Content-Type: application/vnd.ms-excel');
            header('Content-Disposition: attachment;filename='.$fileName);
            header('Cache-Control: max-age=0');
            $objWriter->save('php://output'); //文件通过浏览器下载
        }else{
            $dirname = dirname($fileName);
            if ($dirname != '.') {
                //文件路径如果不存在则递归创健
                CommonFun::recursionMkDir($dirname);
            }
            $objWriter->save($fileName); //脚本方式运行,保存在指定目录
            if(!file_exists($fileName)) {
                return false;
            }
            return true;
        }
    }
    
    self::createExcel($objPHPExcel,$fileName);
    

    谢谢,已经解决了,这是我解决的方法:http://blog.csdn.net/u014273681/article/details/78893911, 虽然还不知道为什么之前没有出现这个问题,我在研究研究

  • 回复了 的回复

    给你个创建excel的方法, 肯定好用

    public static function createExcel(PHPExcel $objPHPExcel = NULL,$fileName = 'example.xlsx',$download = false)
    {
        $objPHPExcel = $objPHPExcel ? $objPHPExcel : new PHPExcel;
        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
        if($download){
            $fileName = basename($fileName);
            $fileName = iconv("utf-8", "gb2312", $fileName);
            header('Content-Type: application/vnd.ms-excel');
            header('Content-Disposition: attachment;filename='.$fileName);
            header('Cache-Control: max-age=0');
            $objWriter->save('php://output'); //文件通过浏览器下载
        }else{
            $dirname = dirname($fileName);
            if ($dirname != '.') {
                //文件路径如果不存在则递归创健
                CommonFun::recursionMkDir($dirname);
            }
            $objWriter->save($fileName); //脚本方式运行,保存在指定目录
            if(!file_exists($fileName)) {
                return false;
            }
            return true;
        }
    }
    
    self::createExcel($objPHPExcel,$fileName);
    

    thank you 我试试

  • 回复了 的回复

    是不是线上数据量太大了?

    不是,线上不大的

  • 回复了 的回复

    报错信息是啥?

    报错信息就是无法访问此网站,网页可能暂时无法连接,或者它已永久性地移动到了新网址。
    ERR_INVALID_RESPONSE

助理 等级规则
110/200
资料完整度
10/100
用户活跃度
0/100

Ta的关注

0

Ta的粉丝

1

Ta的访客

3