There are many php class libraries for operating excel or other files on the Internet, which are also well-developed. For example, incomparable cool PHPExcel, official website: http://www.codeplex.com/PHPExcel online there are a lot of php operations excel or other file class libraries, also done very well. For example, incomparable cool PHPExcel, official website: http://www.codeplex.com/PHPExcel, pear Spreadsheet_Excel_Writer class. However, we only use some of the functions, which will make the program a little bloated. When you call these class libraries, no matter how simple you operate, it will consume a huge amount of memory, which is not desirable for us.
For example, if I need a php excel export program, I only need to export the relevant data to an excel table. in this simple operation, I don't need to use the class libraries or anything. You can simply use the header.
After export, you will find a problem. if the data is a number, unexpected situations may occur. For example, "012345" will be changed to "12345" in excel. if you enter a long number such as an ID card number, it will be represented by scientific notation in excel, in addition, the last four digits may see deviations, 0000 displacement, and so on. In this case, you need to set the cell to the text format.
If the program is UTF-8 encoded, you also need to use the iconv function for transcoding, otherwise it will be garbled.
In other word format, you can specify the header.
Header ("Conten t-Type: application/msword ");
Header ("Content-Disposition: attachment; filename=doc.doc ");
<? Php
Header ("Content-type: application/vnd. ms-excel ");
Header ("Content-Disposition: attachment?filename=export_test.xls ");
$ Tab = "\ t"; $ br = "\ n ";
$ Head = "no.". $ tab. "Remarks". $ br;
// The output content is as follows:
Echo $ head. $ br;
Echo "test321318312". $ tab;
Echo "string1 ";
Echo $ br;
Echo "330181199006061234". $ tab; // The direct output is recognized as a number by Excel.
Echo "number ";
Echo $ br;
Echo "= \" 330181199006061234 \ "". $ tab; // The original output needs to be processed.
Echo "string2 ";
Echo $ br;
?>