zoukankan      html  css  js  c++  java
  • phpexcel 导入导出

            ini_set("memory_limit", "2018M"); // 不够继续加大
            set_time_limit(0);
            $templateName = 'excel.xlsx';
            $objReader = new PHPExcel_Reader_Excel2007();
            if(!$objReader->canRead($templateName)){
                $objReader = new PHPExcel_Reader_Excel5();
                if(!$objReader->canRead($templateName)){
                    echo '无法识别的Excel文件!';
                    return false;
                }
            }
            $arr2 =[];
            $objPHPExcel=$objReader->load($templateName);//导入
                $sheet=$objPHPExcel->getSheet(1);//工作表
                $highestRow=$sheet->getHighestRow();//获取总行数
                for($i= 1 ;$i<$highestRow;$i++)
                {
                    $str =  $sheet->getCell("C$i")->getValue();
                    $arr = explode(',',$str);
                    $a = $sheet->getCell("A$i")->getValue();
                    foreach ($arr as $k=>$v)
                    {
                        $arr2[] = [$a,$v];
                    }
                }
            $objPHPExcel= new PHPExcel();
           foreach ($arr2 as  $k=>$v)
           {
               $k++;
                $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A'.$k,$v[0]);
                $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$k,$v[1]);
           }
           $objWriter =PHPExcel_IOFactory::createWriter($objPHPExcel,'Excel2007');
            $filename = '整理.xlsx';
            ob_end_clean();//清除缓存以免乱码出现
            header('Content-Type: application/vnd.ms-excel');
            header('Content-Type: application/octet-stream');
            header('Content-Disposition: attachment; filename="' . $filename . '"');
            header('Cache-Control: max-age=0');
            $objWriter -> save('php://output');
        }
  • 相关阅读:
    MyBatis查询没有数据返回值为list还是null--------采坑
    Java弱引用WeakReference详细讲解
    idea debug调试详细教程
    [Docker]Dockerfile指令
    [Docker]Dockerfile定制容器
    [Docker]tomcat 404
    [Docker]容器操作
    [Docker]镜像操作
    [Docker]docker-ce安装
    [CentOS7]安装界面直接修改eth0
  • 原文地址:https://www.cnblogs.com/JANCHAN/p/9280586.html
Copyright © 2011-2022 走看看