Home  >  Article  >  Backend Development  >  PHP directly generates excel on the web page to provide download methods

PHP directly generates excel on the web page to provide download methods

WBOY
WBOYOriginal
2016-07-25 08:43:251027browse
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.
  1. header("Content-type:application/vnd.ms-excel");
  2. header("Content-Disposition:filename=test.xls");
  3. echo "test1t";
  4. echo " test2tn";
  5. echo "test1t";
  6. echo "test2tn";
  7. echo "test1t";
  8. echo "test2tn";
  9. echo "test1t";
  10. echo "test2tn";
  11. echo "test1t";
  12. echo "test2tn" ;
  13. echo "test1t";
  14. echo "test2tn";
  15. ?>
Copy code

php, excel


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