• PHP读取excel表格,和导出表格


    读取表格

        public function excel(){
            import("Common.Vendor.Excel.PHPExcel");
            $filename="./files.xlsx";
            $PHPExcel=new PHPExcel();
            import("Common.Vendor.Excel.PHPExcel.Reader.Excel2007");
            $PHPReader=new PHPExcel_Reader_Excel2007();
            $PHPExcel=$PHPReader->load($filename);
            $currentSheet=$PHPExcel->getSheet(0);
            $allColumn=$currentSheet->getHighestColumn();
            $allRow=$currentSheet->getHighestRow();
            for($currentRow=2;$currentRow<=$allRow;$currentRow++){
                $arr['id'] = $PHPExcel->getActiveSheet()->getCell('A'.$currentRow)->getValue();
                $arr['catId'] = $PHPExcel->getActiveSheet()->getCell('B'.$currentRow)->getValue();
                $arr['parentId'] = trim($PHPExcel->getActiveSheet()->getCell('C'.$currentRow)->getValue());
                $arr['name'] = $PHPExcel->getActiveSheet()->getCell('D'.$currentRow)->getValue();
                $arr['catClass'] = $PHPExcel->getActiveSheet()->getCell('E'.$currentRow)->getValue();
                $arr['state'] = $PHPExcel->getActiveSheet()->getCell('F'.$currentRow)->getValue();
                $arr['one'] = $PHPExcel->getActiveSheet()->getCell('G'.$currentRow)->getValue();
                $data[] =$arr;
            }
            return $data ;
        }

    导出表格

        function exportexcel($data=array(),$title=array(),$filename='report'){
            header("Content-type:application/octet-stream");
            header("Accept-Ranges:bytes");
            header("Content-type:application/vnd.ms-excel");
            header("Content-Disposition:attachment;filename=".$filename.".xls");
            header("Pragma: no-cache");
            header("Expires: 0");
            //导出xls 开始
            if (!empty($title)){
                foreach ($title as $k => $v) {
                    $title[$k]=iconv("UTF-8", "GBK",$v);
                }
                $title= implode("	", $title);
                echo "$title
    ";
            }
            if (!empty($data)){
                foreach($data as $key=>$val){
                    foreach ($val as $ck => $cv) {
                        $data[$key][$ck]=iconv("UTF-8", "GBK", $cv);
                    }
                $data[$key]=implode("	", $data[$key]);
                }
                echo implode("
    ",$data);
            }
        }
  • 相关阅读:
    BZOJ 4769: 超级贞鱼 逆序对 + 归并排序
    BZOJ 4897: [Thu Summer Camp2016]成绩单 动态规划
    luogu 4059 [Code+#1]找爸爸 动态规划
    CF718C Sasha and Array 线段树 + 矩阵乘法
    计蒜客 2238 礼物 期望 + 线段树 + 归并
    BZOJ 2157: 旅游 (结构体存变量)
    BZOJ 3786: 星系探索 ETT
    BZOJ 3545: [ONTAK2010]Peaks 启发式合并 + 离线 + Splay
    Spring的几种初始化和销毁方法
    SpringCloud之Zuul高并发情况下接口限流(十二)
  • 原文地址:https://www.cnblogs.com/mthp/p/8349922.html
Copyright © 2020-2023  润新知