How to convert php table to excel

PHPz
Release: 2023-03-05 22:52:02
Original
2686 people have browsed it

How to convert table to excel: first define an "excelData" method; then set the table data, head and header; finally generate it through "excelData($dataResult, $titlename...;)" Excel file is enough.

How to convert php table to excel

Recommendation: "PHP Video Tutorial"

php Generate excel file based on html table

\r\n\r\n\r\n
\r\n"; $str .= "" . $titlename . "
"; $str .= $title; foreach ($datas as $key => $rt) { $str .= ""; foreach ($rt as $k => $v) { $str .= ""; } $str .= "\n"; } $str .= "
{$v}
"; echo $str; header("Content-Type: application/vnd.ms-excel; name='excel'"); header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=" . $filename); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Pragma: no-cache"); header("Expires: 0"); exit($str); } $dataResult = array(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)); $headTitle = "XX保险公司 优惠券赠送记录"; $title = "优惠券记录"; $headtitle = "{$headTitle}"; $titlename = " 合作商户 会员卡号 车主姓名 手机号 车牌号 优惠券类型 优惠券名称 优惠券面值 优惠券数量 赠送时间 截至有效期 "; $filename = $title . ".xls"; excelData($dataResult, $titlename, $headtitle, $filename); echo 'success';
Copy after login

The above is the detailed content of How to convert php table to excel. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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 [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!