Home > Backend Development > PHP Tutorial > PHP output excel format file_PHP tutorial

PHP output excel format file_PHP tutorial

WBOY
Release: 2016-07-13 17:05:02
Original
1042 people have browsed it

php tutorial output excel format file
If you want to use php to output excel format files, you must use header content-type:application/vnd.ms-excel to achieve this. As follows

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

Look at another example of php output excel

header("content-type:application/vnd.ms-excel");
header("content-disposition:filename=test.xls");
echo "a1tb1tc1tna2ta3ta4tn";//r t cell, n new row
?>

require_once("../../config/sys_config.php"); //Configuration file
require_once("../../include/db_class.php"); 
header("content-type: text/html; charset=$page_code"); //Page code
header("content-type:application/vnd.ms-excel");
header("content-disposition:attachment;filename=".mb_convert_encoding("Customer Information Report","gbk",$page_code).".xls");
header("pragma:no-cache");
header("expires:0");
//$usersid = intval( $_get['uid'] ); //User id

//The output content is as follows:
//Output header
echo iconv("utf-8", "gb2312", "Customer Name")."t";
echo iconv("utf-8", "gb2312", "Telephone")."t";
echo iconv("utf-8", "gb2312", "address")."t";
echo iconv("utf-8", "gb2312", "Added date")."t";
echo "n"; //Line break

$sqlstr = "select * from clients where usersid=32 order by clientsid desc";
$rows = $db -> select($sqlstr);
$num = count($rows); //Total number of customers
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"; //Line break
}
?>


Here’s another simple example

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

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

echo "Company name"."t";

echo "username"."t";

echo "password"."t";

echo "second-level domain name"."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";

 }

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630800.htmlTechArticlephp tutorial output excel format file If you want to use php to output excel format file, you must use the header content-type:application /vnd.ms-excel to achieve. As follows ?php $filename = name .'....
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template