Generate an Excel file with PHP

zhaozj2021-02-11  222

Generate an Excel file with PHP

Haha, I learned again today. PHP generation Excel document is too simple, it is estimated that everyone will use, so

Share it.

Everyone is coming to see the code:

Header ("Content-Type: Application / VND.MS-Excel");

Header ("Content-Disposition: FileName = Test.xls");

Echo "TEST1 / T";

ECHO "TEST2 / T / N";

Echo "TEST1 / T";

ECHO "TEST2 / T / N";

Echo "TEST1 / T";

ECHO "TEST2 / T / N";

Echo "TEST1 / T";

ECHO "TEST2 / T / N";

Echo "TEST1 / T";

ECHO "TEST2 / T / N";

Echo "TEST1 / T";

ECHO "TEST2 / T / N";

?>

In the PHP environment running the above code, you can see if the browser asks if the user downloads Excel.

Document, click Save, there will be more Excel files on the hard disk, and you will see using Excel.

The final result, how is it good.

In fact, when doing real applications, you can take data from the database, then follow each

After the end of the data, add / t, each line of data ends, and the method of adding / N, Echo comes out, at the beginning of PHP

With Header ("Content-Type: Application / Vnd.ms-Excel"); indicates that the output is

Excel file, with header ("Content-Disposition: filename = Test.xls");

The file name shows the name of Text.xls. This is OK.

We can modify Header to make him output more formatted files so PHP is handling various types.

The file is more convenient.

Yorgo Sun (Yorgo@163.net)

2000/11/14

Welcome to the reprint, but please ensure the complete documentation, notify the author. Thank you :-)

转载请注明原文地址:https://www.9cbs.com/read-5252.html

New Post(0)