• PHP导出Excel


    <?php
    require_once 'PHPExcel.php';
    require_once 'libs/IOFactory.php';
    require_once 'libs/Excel5.php';
    require_once 'Common_Oper.php';
    class Excel_Oper
    {
        function ArrayToExcel($par_columans,$par_array,$filename)
        {
            try{
            $resultExcel=new PHPExcel();
            $columns=array('A1','B1','C1','D1','E1','F1','G1','H1','I1','J1','K1','L1','M1','L1','O1','P1','Q1','R1','S1','T1','U1','V1','W1','X1','Y1','Z1');    
            $columns2=array('A','B','C','D','E','F','G','H','I','J','K','L','M','L','O','P','Q','R','S','T','U','V','W','X','Y','Z');        
            //表头
            if(is_array($par_columans))
            {
                for($n=0;$n<sizeof($par_columans);$n++)
                {
                    $resultExcel->getActiveSheet()->setCellValue($columns[$n],$par_columans[$n]);
                }
            }
            //标题
            if(is_array($par_array))
            {
                $p=2;
                $com_oper=new Common_Oper();
                if($com_oper->IsNumArray($par_array))
                {
                    for($n=0;$n<sizeof($par_array);$n++)
                    {
                        for($i=0;$i<sizeof($par_array[$n]);$i++)
                        {
                        $resultExcel->getActiveSheet()->setCellValue($columns2[$i].$p,$par_array[$n][$i]);
                        }
                        $p++;
                    }
                }else
                {
                    $p=2;
                    foreach($par_array as $key=>$value)
                    {
                        foreach($par_columans as $key2=>$value2)
                        {
                            $resultExcel->getActiveSheet()->setCellValue($columns2[$key2].$p,$value[$value2]);
                        }
                        $p++;
                    }
                }
            }
            
            $xlswrite=new PHPExcel_Writer_Excel5($resultExcel);
                    $xlswrite->save("E:\4.xls");
            $xlswrite->save("C:\wamp\www\phpstudy\4.xls");
    
            echo '<script>window.location.href=".//4.xls"</script>';
             echo "看结果!";
     
                 
            /*header("Content-Type: application/force-download"); 
            header("Content-Type: application/octet-stream"); 
            header("Content-Type: application/download"); 
            header('Content-Disposition:inline;filename="'.$filename.'"'); 
            header("Content-Transfer-Encoding: binary"); 
            header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 
            header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 
            header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
            header("Pragma: no-cache");
            //$xlswrite->save($filename);
            
            $xlswrite->save( "php://output" );*/
            }catch(Exception $exception)
            {
                echo $exception->getMessage();
            }
        }
    }
    ?>
  • 相关阅读:
    tomcat启动脚本
    libcrypto.so.1.0.0内容丢失导致sshd无法运行解决方案
    linux最小安装
    linux下文件删除的原理
    Web服务器磁盘满故障深入解析
    入驻博客园,新的开始!!!
    其实我们都可以变得更加优秀!
    我的未来在哪里呢!
    学会选择
    SpringBoot+vue.js如何通过post方式实现导出excel
  • 原文地址:https://www.cnblogs.com/zhaobijin/p/5813307.html
Copyright © 2020-2023  润新知