Note that the exported Excel file format is relatively old. after modification, the system will prompt whether to convert it to the updated format. However, you can set the format, which is very powerful.
1. export Excel files in PHP
1: The first recommended cool PHPExcel, official website: http://www.codeplex.com/PHPExcel
Both import and export are supported. the office2007 format can be exported and compatible with 2003.
2. use the Spreadsheet_Excel_Writer class of pear.
: Http://pear.php.net/package/Spreadsheet_Excel_Writer
This class depends on OLE,: http://pear.php.net/package/OLE
Note that the exported Excel file format is relatively old. after modification, the system will prompt whether to convert it to the updated format. However, you can set the format, which is very powerful.
3: Use smarty to generate XML or HTML files conforming to Excel specifications
Supported formats, perfect export solution. However, the imported XML file is essentially an XML file. if it is used for import, additional processing is required.
For more information, see rardge's post: http://bbs.chinaunix.net/viewthread.php? Tid = 745757
Note that if the number of rows of the exported table is unknown, you are advised to delete "ss: ExpandedColumnCount =" 5 "ss: ExpandedRowCount =" 21 "" in the template.
4. use the pack function to print out the broken sentence symbols in the simulated Excel format, which is closer to the standard Excel format. if you use office2003 to modify and save it, no prompt is displayed. this method is recommended. The disadvantage is that there is no format.
5. use tabs and line breaks
The tab character "t" is used to separate columns in the same row. The line break "tn" can be used to open the next row.
6. use com
If your PHP can enable the com MODULE, you can use it to export Excel files.
II. import excel files in php
1. read data in .csv format
Convert .xlsinto a. csv text format, and then use PHP to analyze the file. it is no different from PHP to analyze the text.
Advantages: cross-platform, highly efficient, and readable/writable.
Disadvantage: only .csvfiles can be directly used. if .xls binary files are often accepted, they must be manually converted and cannot be automated. A file has only one SHEET.
PHP self-contained analysis. csv function: fgetcsv
2. ODBC link data source
Advantages: supports multiple formats, such as cvs and xls. Supports read/write and uses standard SQL languages, which are almost the same as SQL Server and MYSQL databases.
Disadvantage: windows servers are supported.
3. PHP custom class
Advantage: cross-platform. Some classes support write operations. Supports. xls binary files
Common classes include phpExcelReader and PHPExcel. The latter supports read/write, but php5.2 or above is required.
PhpExcelReader is used to read files. Returns an array containing all the contents of the table.