• 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');
        }
  • 相关阅读:
    p4 view mapping及其特殊字符
    Build Release Blogs
    Linux技术blogs
    为什么使用tmux
    linux下安装wine
    PythonDjango的windows环境
    tmux安装
    基于云端的开发平台Team Foundation Service
    linux网络配置之setup命令
    Centos6.2设置静态ip和dns
  • 原文地址:https://www.cnblogs.com/JANCHAN/p/9280586.html
Copyright © 2020-2023  润新知