zoukankan      html  css  js  c++  java
  • 导出excel

    <?php
    function excelData($datas,$titlename,$title,$filename){ 
        $str = "<html xmlns:o="urn:schemas-microsoft-com:office:office"
    xmlns:x="urn:schemas-microsoft-com:office:excel"
    xmlns="http://www.w3.org/TR/REC-html40">
    <head>
    <meta http-equiv=Content-Type content="text/html; charset=utf-8">
    </head>
    <body>"; 
        $str .="<table border=1><head>".$titlename."</head>"; 
        $str .= $title; 
        foreach ($datas  as $key=> $rt ) 
        { 
            $str .= "<tr>"; 
            foreach ( $rt as $k => $v ) 
            { 
                $str .= "<td>{$v}</td>"; 
            } 
            $str .= "</tr>
    "; 
        } 
        $str .= "</table></body></html>"; 
        header( "Content-Type: application/vnd.ms-excel; name='excel'" ); 
        header( "Content-type: application/octet-stream" ); 
        header( "Content-Disposition: attachment; filename=".$filename.".xls" ); 
        header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" ); 
        header( "Pragma: no-cache" ); 
        header( "Expires: 0" ); 
        exit( $str ); 
    }
    
    $datas = [["a","a","a","a"],["b","b","a","a"],["c","c","a","a"]];
    $titlename = "abc";
    $title = "123";
    $filename = "表单";
    excelData($datas,$titlename,$title,$filename);
  • 相关阅读:
    SDOI2018 旧试题
    JSOI2004 平衡点 / 吊打XXX
    SDOI2017 数字表格
    CQOI2015 选数
    BZOJ2741 【FOTILE模拟赛】L
    BZOJ4103 [Thu Summer Camp 2015]异或运算
    BZOJ3689 异或之
    BZOJ4128 Matrix
    HNOI2006 最短母串问题
    SCOI2013 密码
  • 原文地址:https://www.cnblogs.com/liu-heng/p/7607500.html
Copyright © 2011-2022 走看看