Home  >  Article  >  Backend Development  >  Simple sample code for php to export word documents and excel spreadsheets_PHP tutorial

Simple sample code for php to export word documents and excel spreadsheets_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:37:11941browse

Code to generate word:

Copy code The code is as follows:

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

Code to generate excel:
Copy code The code is as follows:

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

But you will also encounter it during the import process There are many problems. For example, when exporting Excel, if a certain column exports an ID number, you will find that the ID number automatically uses scientific notation after opening the Excel file. No matter how you modify the attributes of the column, you will not be able to achieve your requirements online. Some people say that there will be no problem if you first change the column attribute to text and then input it. This is indeed the case in Excel, but it cannot be done when exporting from the PHP program. Some people also say that they have tried adding single quotes before the ID number. It doesn’t work either. Finally, the problem of adding a space before the exported ID number data is solved. The space is the space of the html code. The problem is solved
.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/736781.htmlTechArticleCode to generate word: Copy the code as follows: header("Content-type: application/octet-stream") ; header("Accept-Ranges: bytes"); header('Content-type: application/doc'); header(...
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