Home > php教程 > php手册 > 轻松实现PHP输出excel

轻松实现PHP输出excel

WBOY
Release: 2016-06-13 10:38:28
Original
1223 people have browsed it

  要将PHP数据输出到excel表格上,PHP在这方面的支持非常好,PHP只需简单几句就可以输出一个简单的excel表。

  PHP代码:

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

  header("Content-Disposition:attachment;filename=users.xls" );

  echo "公司名称"." ";

  echo "用户名"." ";

  echo "密码"." ";

  echo "二级域名"." ";

  echo " ";

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

  echo "$val->ComName"." ";

  echo "$val->UserName"." ";

  echo "$val->UserTruePw"." ";

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

  echo " ";

  }

  ?>

  注意编码问题,因为表格一般输出是utf-8 编码。我用表格形式(table+tr+td)输出的时候就出现了乱码。。。。因为我页面编码是GB2312,可用iconv转也行,为了防止乱码自己又搞不定,最好用上面方法输出.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template