php輸出excel格式檔案_PHP教程

來源:互聯網
上載者:User
php教程輸出excel格式檔案
如果要利用了php輸出excel格式檔案就必須利用header content-type:application/vnd.ms-excel來實現。如下

$filename = name .'.xls';
header("content-type:application/vnd.ms-excel");
header("content-disposition:attachment;filename=$filename");
?>

再看一php輸出excel執行個體

header("content-type:application/vnd.ms-excel");
header("content-disposition:filename=test.xls");
echo "a1tb1tc1tna2ta3ta4tn";//r t儲存格,n新一行
?>

require_once("../../config/sys_config.php"); //設定檔
require_once("../../include/db_class.php");
header("content-type: text/html; charset=$page_code"); //頁面編碼
header("content-type:application/vnd.ms-excel");
header("content-disposition:attachment;filename=".mb_convert_encoding("客戶資料報表","gbk",$page_code).".xls");
header("pragma:no-cache");
header("expires:0");
//$usersid = intval( $_get['uid'] ); //使用者id

//輸出內容如下:
// 輸出表頭
echo iconv("utf-8", "gb2312", "客戶名稱")."t";
echo iconv("utf-8", "gb2312", "電話")."t";
echo iconv("utf-8", "gb2312", "地址")."t";
echo iconv("utf-8", "gb2312", "添加日期")."t";
echo "n"; //換行

$sqlstr = "select * from clients where usersid=32 order by clientsid desc";
$rows = $db -> select($sqlstr);
$num = count($rows); //客戶總數
for( $i = 0; $i < $num; $i++ )
{
echo iconv("utf-8", "gb2312",$rows[$i][clientsname])."t";
echo iconv("utf-8", "gb2312",$rows[$i][clientsphone])."t";
echo iconv("utf-8", "gb2312",$rows[$i][clientsaddress])."t";
echo iconv("utf-8", "gb2312",$rows[$i][clientstime])."t";
echo "n"; //換行
}
?>


再來一款簡單一實例

header("content-type:application/vnd.ms-excel");

  header("content-disposition:attachment;filename=users.xls" );

  echo "公司名稱"."t";

  echo "使用者名稱"."t";

  echo "密碼"."t";

  echo "次層網域"."t";

  echo "n";

  foreach($result['result'] as $val){

  echo "$val->comname"."t";

  echo "$val->username"."t";

  echo "$val->usertruepw"."t";

  echo emptyempty($val->domainname)?'':('http://'.$val->domainname.'.jiaomai.com')."t";

  echo "n";

  }

http://www.bkjia.com/PHPjc/630800.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/630800.htmlTechArticlephp教程輸出excel格式檔案 如果要利用了php輸出excel格式檔案就必須利用header content-type:application/vnd.ms-excel來實現。如下 ?php $filename = name .'....

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.