Home  >  Article  >  Backend Development  >  How to convert php html to excel

How to convert php html to excel

藏色散人
藏色散人Original
2020-08-15 10:17:503362browse

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");

This is a complete PHP file:

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

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!

Statement:
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
Previous article:How to clear style in phpNext article:How to clear style in php