Home > Article > Backend Development > PHP directly generates excel on the web page to provide download methods
Run the above code in the php environment, and you can see the browser asking the user whether to download the excel document, click Save, and there will be an extra excel file on the hard disk. Open it with excel and you will see the final result. How good is it? .
In fact, when making a real application, you can take the data out of the database, and then echo it out by adding t at the end of each column of data and n at the end of each row of data. Use header("Content at the beginning of php -type:application/vnd.ms-excel"); indicates that the output is an excel file. Use header("Content-Disposition:filename=test.xls"); to indicate that the output file name is text.xls. That's OK.
|