PHP sets HTTP header information to export Excel report

巴扎黑
Release: 2016-11-08 10:53:41
Original
1248 people have browsed it

No need to use fputcsv function to generate reports. Just set the corresponding format and HTTP header information to generate the report. Attached code:

<?php
header("Content-type: application/vnd.ms-excel; charset=utf-8");
header("Content-Disposition: attachment; filename=excel.xls");
$data  = "分类销售统计\t\n";
$data .= "排名\t产品大类\t销售额(万)\t销售占比\t单品数量\n";
if (EC_CHARSET == &#39;utf-8&#39;)
{
      echo ecs_iconv(EC_CHARSET, &#39;GB2312&#39;, $data);
}
else
{
      echo $data;
}
?>
Copy after login

Note: The character conversion step can be omitted according to actual needs.

Related labels:
php
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