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 {
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";
}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version
Chinese version, very easy to use

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Zend Studio 13.0.1
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
