Home >Backend Development >PHP Problem >How to convert php html to excel
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.
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 .= ""; echo $data. "\t"; ?>…… "; $data .= "…… "; $data .= "…… "; $data .= "…… "; $data .= "…… "; $data .= "
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!