zoukankan      html  css  js  c++  java
  • thinkphp3.2 phpexcel导入

    
    
    //导入
    public
    function textImp(){ //框架上传文件 $upload = new ThinkUpload(); $upload->maxSize = 3145728; $upload->exts = array('xlsx'); $upload->rootPath = './Public/uploads/'; $upload->savePath = ''; $info = $upload->upload(); $filename = './Public/uploads/' . $info["updataexcel2007"]["savepath"] . $info["updataexcel2007"]["savename"]; //上传成功后的文件 vendor("PHPExcel.PHPExcel"); //导入类库 $objPhpExcel = PHPExcel_IOFactory::load($filename); /* * @param mixed 表格为空时返回的值 * @param boolean 是否启用公式计算 * @param boolean 是否格式化单元格 * @param boolean 返回的行和列 */ $result = $objPhpExcel->getActiveSheet()->toArray(true, true, true, true); //对数据业务处理 }
    
    
    //导出
    public
    function textDown(){ vendor("PHPExcel.PHPExcel"); $objExcel = new PHPExcel(); $objPhpExcel = new PHPExcel_Writer_Excel2007($objExcel); //表头 $objExcel->getActiveSheet() ->setCellValue('A1','name1') ->setCellValue('B1','name2'); //内容 $objExcel->getActiveSheet() ->setCellValue('A2','xx1') ->setCellValue('B2','xx2'); //header信息 header("Pragma: public"); //可以缓存响应中的信息 header("Expires: Thursday January 11th 2018"); //GMT格式的时间 时间过期则阻止缓存 header("Cache-Control:must-revalidate, post-check=0, pre-check=0"); // 3个header 输出不缓存 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='text.xlsx'"); header("Content-Transfer-Encoding:binary"); // $objwriter = PHPExcel_IOFactory::createWriter($objPhpExcel, 'Excel5'); $objPhpExcel->save('php://output'); }

      

  • 相关阅读:
    小知识:关于String的创建
    JSON学习笔记,数组
    JSON学习笔记,对象
    爱乐之城 La La Land
    TwoSampleMR包出现报错: None of the specified columns present
    无亲缘关系为何IBD结果为同卵双胞胎/重复样本
    本周最新文献速递20210321
    本周最新文献速递20210314
    使用 KaKs Calculator 计算 KaKs 的衍生问题解答
    本周最新文献速递20210307
  • 原文地址:https://www.cnblogs.com/limonyun/p/9390846.html
Copyright © 2011-2022 走看看