How to import and export Excel files using PHP

Source: Internet
Author: User
How to import and export Excel files using PHP
This article describes how to import and export excel files in php, how to export excel files using phpexcel or Spreadsheet_Excel_Writer, and how to export csv files.

1. PHP exports the Excel file 1. phpexcel is recommended. official website: http://www.codeplex.com/phpexcelimport and export are all in the format of office2007format, compatible

2. Spreadsheet_Excel_Writer class using pear: bytes. However, you can set the format, which is very powerful. 3. use smarty to generate XML or HTML files that comply with Excel specifications. this is a perfect export solution. However, the imported XML file is essentially an XML file. if it is used for import, additional processing is required.

Note: If the number of rows of the exported table is unknown, it is best 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 the tab and line feed method tab "\ t" to split the columns in the same row, and use the line break "\ t \ n" to open the next row.

6. use com. If PHP can enable the com MODULE, you can use it to export Excel files.

2. PHP imports the excelfile 1. convert .xlsto the text format of .csv in the format of .csvformat, 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. Advantages of using ODBC to link data sources: Support for 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 advantages: cross-platform. Some classes support write operations. Common classes supporting. xls binary files 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.

>>> Articles you may be interested in: php export excel table comprehensive example phpExcel export excel add hyperlink instance code PHP export excel convert number into scientific count solution PHP export EXCEL simple example export excel use phpexcel class library export excelphpexcel export excel example of exporting excel files from a classic instance in php format php export excel instance code php export excel (constantly refresh the buffer) instance code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.