基于codeigniter3框架使用PHPspreadsheet包实现excel模板导出文件

3 篇文章 0 订阅

基于codeigniter3框架使用PHPspreadsheet包实现excel模板导出文件

具体使用

  • 具体调用方法
/**
    * 方法 export_project_apply_detail_after_samp_as_excel_by_template_serv,通过excel模板导出项目抽检申请测量后详情数据到excel
    *
    * @param array $params 参数数组
    *
    * @return mixed 成功返回true,失败返回false
    */
   public function export_project_apply_detail_after_samp_as_excel_by_template_serv(array $params){
       $this->load->helper('project_apply_export_excel');

       /*//获取项目抽检申请详情(包含项目地址所属公司等信息)
       $project_apply_department = $this->get_project_apply_department_detail_serv($params);
       //获取项目抽检申请检查项列表
       $resolve_item_list = $this->deal_get_project_apply_item_list_serv($params);*/

       //获取项目公司检查项及测量数据
       $project_apply_department = $this->get_m_project_apply_samp_report_serv($params);

       //处理成可写入excel的数据格式
       /*echo '<pre>';
       var_dump($project_apply_department);
       die();*/
       $excel_data = h_export_project_apply_detail_after_samp_as_excel_by_template($project_apply_department);
       //通过工厂模式创建内容
       try{
           $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load(FCPATH.'public/template/单个公司导出抽检详细Excel表3.xls');
           $worksheet = $spreadsheet->getActiveSheet();

           //填充数据
           foreach($excel_data as $k => $v){
               $worksheet->getCell($k)->setValue($v);
           }

           //生成文件到oss
           $oss_path = 's_c_s_l/excel/';
           $save_path = getcwd().'/'.$oss_path;
           $file_ext = 'xls';
           $file_name = $project_apply_department['project_name'].'-实测实量现场记录表';

           //通过工厂模式来写内容
           $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, ucfirst($file_ext));
           $writer->save($save_path.$file_name.'.'.$file_ext);

           $export_res = true;
           //导出,在浏览器输出二进制流主动生成excel文件
           if($export_res){
               $export_res = [
                   'oss_path' => $oss_path.$file_name.'.'.$file_ext,
                   'local_full_path' => $save_path.$file_name.'.'.$file_ext,
               ];
           }
           return $export_res;
       }catch (Exception $e){
           return false;
       }
   }

支付宝
在这里插入图片描述

********************只要思想不滑坡,办法总比困难多********************
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值