• thinkphp5中引入第三方扩展的方法extend


    thinkphp5中引入第三方扩展的方法extend

    玩的还是phpexcel

    目录里面的文件夹是

    使用方法

    1 控制器顶部 加入

    use thinkLoader;

    2 控制器的函数里面

     Loader::import("phpexcel.PHPExcel");

    整个文件代码

    <?php
    
    namespace appadmincontroller;
    
    // use app	hinkController;
    use appcommoncontrollerBackend;
    use appadminmodelSecurityCode as SecurityCodeModel;
    use thinkRequest;
    use thinkLoader;
     
    
    class SecurityCode extends Backend
    {
         
    
        //导出
        public function Output()
        {
            $cc = new SecurityCodeModel();
            $info = $cc->order('id')->select();
    
            $data=array();   
            foreach($info as $k=>$v) {
                $data[$k]['id']=$v['id'];
                $data[$k]['serial_number']=$v['serial_number'];
                // $data[$k]['code1']=$v['code1'];
                // $data[$k]['code2']=$v['code2'];
                // $data[$k]['is_active']=$v['is_active'];
                // $data[$k]['product_code']=$v['product_code'];
                // $data[$k]['line']=$v['line'];
                // $data[$k]['xuhao']=$v['xuhao'];
                $data[$k]['batch']=$v['batch'];
            }
             
            $filename='序列号';
            $field = array(
                'A' => array('id', '序号'),
                'B' => array('serial_number', '序列号'),
                'C' => array('batch', '批次'),
            );
            //$this->downloadExcel($data,$title,$filename);
            $this->phpExcelList($field,$data,$filename);
                
             
        }
        
        /**
         * 直接导出需要生产的内容
         * @param $field
         * @param $list
         * @param string $title
         * @throws PHPExcel_Exception
         * @throws PHPExcel_Writer_Exception
         */
        public function phpExcelList($field, $list, $filename='文件')
        {
            //vendor("PHPExcel.PHPExcel");
            Loader::import("phpexcel.PHPExcel");//引入phpexcel文件夹下的PHPExcel
            $objPHPExcel = new PHPExcel();
            $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel); //设置保存版本格式
            foreach ($list as $key => $value) {
                foreach ($field as $k => $v) {
                    if ($key == 0) {
                        $objPHPExcel->getActiveSheet()->setCellValue($k . '1', $v[1]);
                    }
                    $i = $key + 2; //表格是从2开始的
                    $objPHPExcel->getActiveSheet()->setCellValue($k . $i, $value[$v[0]]);
                }
            }
            header("Pragma: public");
            header("Expires: 0");
            header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
            header("Content-Type:application/force-download");
            header("Content-Type:application/vnd.ms-execl");
            header("Content-Type:application/octet-stream");
            header("Content-Type:application/download");;
            header('Content-Disposition:attachment;filename='.$filename.'.xls');
            header("Content-Transfer-Encoding:binary");
            $objWriter->save('php://output');
        }
        
       
       
    }
  • 相关阅读:
    简单的REST的框架实现
    将 Shiro 作为一个许可为基础的应用程序 五:password加密/解密Spring应用
    Java自注三进入
    hdu 4803 贪心/思维题
    SSH框架总结(框架分析+环境搭建+实例源代码下载)
    Rational Rose 2007 &amp;Rational Rose 2003 下载及破解方法和汉化文件下载
    hdu 5014 思维题/推理
    电脑蓝屏出现事件7000
    大豆生物柴油驱动的大巴斯(Bus)
    POJ 3481 &amp; HDU 1908 Double Queue (map运用)
  • 原文地址:https://www.cnblogs.com/baker95935/p/12484863.html
Copyright © 2020-2023  润新知