PHP Import and export Excel files

Source: Internet
Author: User
Tags ole pear mysql database

First, PHP export Excel files

1: The first recommendation of the Phpexcel, official website: http://www.codeplex.com/PHPExcel
Import export, you can export office2007 format, compatible with 2003

2, use Pear's Spreadsheet_excel_writer class
Download Address: Http://pear.php.net/package/Spreadsheet_Excel_Writer
This class is dependent on OLE, download address: Http://pear.php.net/package/OLE
It is important to note that the exported Excel file format is older, and saving after modification prompts you to convert to the updated format. But the format can be set, very powerful.
3: Use Smarty to generate XML or HTML files that conform to the Excel specification
Support format, very perfect export scheme. However, it is essentially an XML file, and if used for import it needs to be handled separately.
For more information, please see Rardge's post: http://bbs.chinaunix.net/viewthread.php?tid=745757
Note that if the exported table row number is uncertain, it is best to delete the "ss:expandedcolumncount=" 5″ss:expandedrowcount= "21″" in the template.
4, the use of pack function to print the simulation of Excel format punctuation symbol, this is closer to the standard format of Excel, with office2003 modified to save, will not pop-up prompts, recommended this method. The disadvantage is that there is no format.
5, the use of tabs, line-feed method
The tab "\ T" user splits a column in the same row, and the newline character "\t\n" can open the next line.
6, using COM
If your PHP can open a COM module, you can use it to export Excel files

Second, PHP import Excel file

1. Read in. csv format
Converting. xls to a. csv text format and then parsing the file in PHP is no different from the PHP parsing text.
Advantages: Cross-platform, high efficiency, can read and write.
Disadvantage: You can only use. csv files directly, if you often accept. xls binaries require manual conversion and cannot be automated. A file has only one sheet.

PHP has its own analysis. csv function: fgetcsv

2. ODBC Linked data source

Advantages: Support A variety of formats, CVS, XLS and so on. Support Read and write, using standard SQL language, and SQL Server, MySQL database almost exactly the same.
Disadvantage: Value supports Windows Server

3. PHP Custom Class

Advantages: cross-platform. Some classes support write operations. Support. xls binaries
The commonly used classes are phpexcelreader and Phpexcel. The latter support reading and writing, but need to php5.2 the above version.

Phpexcelreader is specifically used to read files. Returns an array that contains all the contents of the table.



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.