Home > Backend Development > PHP Problem > How to convert php html to excel

How to convert php html to excel

藏色散人
Release: 2023-03-04 14:06:01
Original
3485 people have browsed it

php How to convert html to excel: First open the html file; then add the statement [header("Content-Disposition: attachment;filename=filename.xls");] to the header of the html.

How to convert php html to excel

Recommended: "PHP Video Tutorial"

Take php as an example to directly use html to generate excel files

In the past, tools such as PHPExcel were used to generate Excel, which is very powerful, but sometimes we just want a simple data output, and using those is a bit cumbersome. I happened to discover a very simple method recently, so I recorded it.

Here we mainly use Content-Type to achieve the functions we want, and then use programming languages ​​such as PHP to obtain the data we want.

Add the following two sentences to the html header to download your web page content directly as an .xls attachment

header("Content-type: application/vnd.ms-excel; charset=utf8");
header("Content-Disposition: attachment; filename=filename.xls");
Copy after login

This is a complete PHP file:

";
$data .= "";
$data .= "……";
$data .= "……";
$data .= "……";
$data .= "……";
$data .= "……";
$data .= "";
$data .= "";
echo $data. "\t";
?>
Copy after login

Of course, you can also read from the database or loop to generate some data to fill excel.

The above is the detailed content of How to convert php html 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 admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template