php exports simple sample code for word documents and excel spreadsheets

  • 2021-01-22 04:58:11
  • OfStack

The code to generate word:

 header("Content-type: application/octet-stream");
 header("Accept-Ranges: bytes");
 header('Content-type: application/doc');
 header('Content-Disposition: attachment; filename=" test .doc"');

The code to generate excel:

Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Content-type:application/vnd.ms-excel");
Header("Content-Disposition:attachment;filename=" test .xls"');

However, there will also be many problems in the process. For example, if excel is exported and the ID number of a certain column is exported, after opening excel file, it will be found that the ID number automatically adopts scientific counting method. No matter how to modify the column attributes, it cannot achieve its requirements. Some people on the Internet say that it is OK to change the column attribute to text first and then enter it. This is true for excel, but it is not possible for php programs to export this column. Some people also say that in the ID number before the single quotation marks, tried not to, finally in the export of the ID number data before the space to solve the problem, the space is the html code space. Problem solving.

Related articles: