PHP-ExcelReader: PHP class library used to parse excel files,

Source: Internet
Author: User

PHP-ExcelReader: PHP class library used to parse excel files,

PHP-ExcelReader is an open-source PHP-based project that parses excel files.

The official PHP-ExcelReader website is as follows:

Http://phpexcelreader.sourceforge.net/

Shows the structure of the downloaded file:


The two files reader. php and oleread. inc in the Excel directory are mandatory for excel parsing. The classes and methods required for parsing are written in these two files respectively. Specifically, the two files example.php and example2.php are the example program. The jxlwtest.xls file is the file to be parsed by the sample program, and the remaining two files are the self-report files.

 

PHP-ExcelReader is easy to use. The following code is required:

[Php]View plaincopy
  1. Require_once ('excel/reader. php'); // reference the Excel/reader. php file and load the class library
  2. $ Reader = new Spreadsheet_Excel_Reader (); // instantiate the parsing class Spreadsheet_Excel_Reader
  3. $ Reader-> setOutputEncoding ("CP1251"); // you can specify the encoding method.
  4. $ Reader-> read ("jxlwtest.xls"); // read and Extract files (jxlwtest.xls is the file name)

After the preceding four statements are executed, the excel file is parsed. The parsed result is in the array$ Reader-> sheets [0]Contains maxrow, maxcol, numRows, numCols, cells, and cellsInfo, among which numRows (number of rows), numCols (number of columns), and cells (cell content) are useful ). To obtain the specific data information of an excel file, traverse$ Reader-> sheets [0] ["cells"]Array. This array is like

$ Reader-> sheets [0] ["cells"] [<row index>] [<column index>] = <cell value>

The two-dimensional array, row index and column index are counted from 1.

 

Note:

1.The Excel/reader. php file already uses require_once to include the oleread. inc file. Therefore, you do not need to load oleread. inc during the call.

2.The Excel file jxlwtest.xls of the official website is damaged and cannot be read or parsed.

3.The following error occurs when the first line of the original Excel/reader. php file is as follows:

Require_once 'spreadsheet/Excel/Reader/OLERead. php ';

The reason is that the Spreadsheet/Excel/Reader/OLERead. php file does not exist. In fact, the file needed here is Excel/oleread. inc. Change the file name after require_once to 'oleread. inc.

4.The following warning is reported when the row 261st of the original Excel/reader. php file is returned:

Deprecated: Assigning thereturn value of new by reference is deprecated

The reason is that the = & symbol of this line has been deprecated in PHP 5.3. Based on the role of this symbol, you can directly change it to =.

5.PHP-ExcelReader does not support parsing Excel 2007 documents. That is to say, Excel files with the xlsx extension cannot be parsed using this class library. It only targets Excel files with the xls extension.

6.The PHP-ExcelReader encoding method is based on the iconv command. The parameter of setOutputEncoding is the name of the character set to be set. To make this method take effect, you need to install the iconv extension for the local PHP environment. If the local PHP environment does not have the iconv extension, the PHP-ExcelReader encoding method defaults to Unicode. For the iconv command, see the following link:

Http://www.cnblogs.com/xuxm2007/archive/2010/11/09/1872379.html

7.PHP-ExceReader may encounter an error in precision when parsing integers. For example, 58 is resolved to 57.5 for unknown reasons. All you can do is check the data after parsing and rounding it out (if necessary ).

8.For blank cells in an excel file, PHP-ExcelReader directly skips the blank cells that are not stored in the result array, or saves them as 0 or "" (empty string ).

PHP-ExcelReader is an open-source PHP-based project that parses excel files.

The official PHP-ExcelReader website is as follows:

Http://phpexcelreader.sourceforge.net/

Shows the structure of the downloaded file:


The two files reader. php and oleread. inc in the Excel directory are mandatory for excel parsing. The classes and methods required for parsing are written in these two files respectively. Specifically, the two files example.php and example2.php are the example program. The jxlwtest.xls file is the file to be parsed by the sample program, and the remaining two files are the self-report files.

 

PHP-ExcelReader is easy to use. The following code is required:

[Php]View plaincopy
  1. Require_once ('excel/reader. php'); // reference the Excel/reader. php file and load the class library
  2. $ Reader = new Spreadsheet_Excel_Reader (); // instantiate the parsing class Spreadsheet_Excel_Reader
  3. $ Reader-> setOutputEncoding ("CP1251"); // you can specify the encoding method.
  4. $ Reader-> read ("jxlwtest.xls"); // read and Extract files (jxlwtest.xls is the file name)

After the preceding four statements are executed, the excel file is parsed. The parsed result is in the array$ Reader-> sheets [0]Contains maxrow, maxcol, numRows, numCols, cells, and cellsInfo, among which numRows (number of rows), numCols (number of columns), and cells (cell content) are useful ). To obtain the specific data information of an excel file, traverse$ Reader-> sheets [0] ["cells"]Array. This array is like

$ Reader-> sheets [0] ["cells"] [<row index>] [<column index>] = <cell value>

The two-dimensional array, row index and column index are counted from 1.

 

Note:

1.The Excel/reader. php file already uses require_once to include the oleread. inc file. Therefore, you do not need to load oleread. inc during the call.

2.The Excel file jxlwtest.xls of the official website is damaged and cannot be read or parsed.

3.The following error occurs when the first line of the original Excel/reader. php file is as follows:

Require_once 'spreadsheet/Excel/Reader/OLERead. php ';

The reason is that the Spreadsheet/Excel/Reader/OLERead. php file does not exist. In fact, the file needed here is Excel/oleread. inc. Change the file name after require_once to 'oleread. inc.

4.The following warning is reported when the row 261st of the original Excel/reader. php file is returned:

Deprecated: Assigning thereturn value of new by reference is deprecated

The reason is that the = & symbol of this line has been deprecated in PHP 5.3. Based on the role of this symbol, you can directly change it to =.

5.PHP-ExcelReader does not support parsing Excel 2007 documents. That is to say, Excel files with the xlsx extension cannot be parsed using this class library. It only targets Excel files with the xls extension.

6.The PHP-ExcelReader encoding method is based on the iconv command. The parameter of setOutputEncoding is the name of the character set to be set. To make this method take effect, you need to install the iconv extension for the local PHP environment. If the local PHP environment does not have the iconv extension, the PHP-ExcelReader encoding method defaults to Unicode. For the iconv command, see the following link:

Http://www.cnblogs.com/xuxm2007/archive/2010/11/09/1872379.html

7.PHP-ExceReader may encounter an error in precision when parsing integers. For example, 58 is resolved to 57.5 for unknown reasons. All you can do is check the data after parsing and rounding it out (if necessary ).

8.For blank cells in an excel file, PHP-ExcelReader directly skips the blank cells that are not stored in the result array, or saves them as 0 or "" (empty string ).

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