zoukankan      html  css  js  c++  java
  • PHP导出Excel简单实例

    <?php
    header("Content-type:application/vnd.ms-excel");
    header("Content-Disposition:attachment;filename=table.xls");
    ?>
      <table border="1">
        <tr>
          <td>t00</td><td>t01</td><td>t02</td>
        </tr>
        <tr>
          <td>t10</td><td>t11</td><td>t12</td>
        </tr>
        <tr>
          <td>t20</td><td>t21</td><td>t22</td>
        </tr>
      </table>

    只要有则文档相当于xls文件:

    header("Content-type:application/vnd.ms-excel");
    header("Content-Disposition:attachment;filename=table.xls");

    需要写入了再导出,可参考以下例子:

    	//文件写入
     $files="mei_excel_write.php";
    
     if(!is_writable($files)){    		//判断文件是否可写
      echo"<font color=red>不可写</font>";
     }else{
      echo"<font color=green>可写</font>";
     }
    $time=date("Y-m-d H:i:s");
     if(isset($_POST['write'])){  		//把信息写入文件
      $str="<?php";
      $str.="\n";
      $str.="header(\"Content-type:application/vnd.ms-excel\");";
      $str.="\n";
      $str.="header(\"Content-Disposition:attachment;filename=".$time.".xls\");";
        $str.="\n";
      $str.="?>";
     $str.="\n";
    $str.="<table border=\"1\">";
    $str.="<tr>";
    $str.="<td>ID</td>";
    $str.=" </tr>";
      while ($row = mysql_fetch_array($query))					{ 
    	$str.=" <tr>";	
    	$str.="<td>".$st."</td>";  
    	$str.=" </tr>"; 	                 
       }                   
    

      

  • 相关阅读:
    200. Number of Islands(DFS)
    DoubleDQN---tensorflow实现
    133. Clone Graph(图的复制)
    python deque
    136. Single Number(位运算)
    C++中位运算
    anacoda 安装默认源中没有的包
    kali系统安装图文教程
    C#基础|初探反射
    一般处理程序(ashx)和页面处理程序(aspx)的区别
  • 原文地址:https://www.cnblogs.com/tinyphp/p/2793182.html
Copyright © 2011-2022 走看看