How to import and export Excel files in PHP

Source: Internet
Author: User
Tags ole pear
This article describes the way to import and export Excel files in PHP, using the Phpexcel or Spreadsheet_excel_writer class to export Excel files, and describes the three ways to export a CSV file.

One, PHP export Excel file 1, recommended Phpexcel, official website: Import and export, you can export office2007 format, and compatible with 2003

2, use Pear spreadsheet_excel_writer class Download Address: Http:// This class relies on OLE, download address: http :// Note that the exported Excel file format is older and will prompt you to convert to an updated format when you modify it. But you can set the format, very powerful. 3, using smarty, generate XML or HTML file support format that conforms to Excel specification, very perfect export scheme. However, the nature of the derivative is the XML file, if used to import it needs to be processed separately.

Note that if the number of table rows exported is uncertain, it is best to delete "ss:expandedcolumncount=" 5″ss:expandedrowcount= "21″" in the template. 4, using the Pack function to print the analog Excel format of the segmentation symbol, which is closer to the standard format of Excel, with office2003 modified to save, will not pop up hints, recommend this method. The disadvantage is no format.

5, the use of tabs, newline character method tab "\ T" user split the column in the same row, line break "\t\n" can open the next line.

6, using COM if PHP can open the COM module, you can use it to export Excel files

Second, PHP import Excel file 1, in the. csv format to convert. xls into a. csv text format, and then use PHP to parse this file, and PHP analysis text is no different. Advantages: Cross-platform, high efficiency, can read and write. Cons: You can only use. csv files directly, if you often accept. xls binaries, you need to convert them manually, not automatically. A file has only one sheet. PHP has its own analysis. csv function: fgetcsv

2,ODBC link Data Source Advantages: Support multiple formats, CVS, XLS, etc. Supports read and write, using the standard SQL language, almost identical to SQL Server, MySQL database. Disadvantage: The value supports Windows Server

3,php Advantages of custom classes: cross-platform. Some classes support write operations. Support for. xls binaries commonly used classes are Phpexcelreader, Phpexcel. The latter supports read and write, but requires php5.2 or more. The Phpexcelreader is designed to read files. Returns an array that contains all the contents of the table.

>>> you may be interested in the article: PHP export Excel form Synthesis example Phpexcel export Excel plus hyperlink instance code PHP export Excel when numbers become scientific counting solution PHP Simple example of exporting Excel Export the classic instance of Excel using the Phpexcel class library export Excelphpexcel Example of PHP export Excel format file PHP Export instance code for Excel PHP export Instance code for Excel (constantly flush buffers)

  • Related Article

    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: 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.