Excelreader:php-excelreader: PHP class library for parsing Excel files

Source: Internet
Author: User
Tags array character set deprecated php class php file php and php code

Php-excelreader: PHP class library for parsing Excel files

Php-excelreader is an Open-source project based on PHP, which is designed to parse Excel files.
Among them, two files in the Excel directory reader.php and Oleread.inc are the files that Excel resolves must contain, the classes and methods required for parsing are written in these two files respectively. Other, example.php and example2.php Two files are sample programs, Jxlwtest.xls files are files that the sample program needs to parse, and the remaining two files are readme files.
The use of Php-excelreader is simpler, and the following four code is required:
PHP code
Require_once (' excel/reader.php '); referencing excel/reader.php files, loading class libraries

$reader = new Spreadsheet_excel_reader (); Materialized parsing class Spreadsheet_excel_reader

$reader->setoutputencoding ("CP1251"); Set encoding mode

$reader->read ("Jxlwtest.xls"); Read and parse the file (Jxlwtest.xls as file name)
Require_once (' excel/reader.php '); Referencing excel/reader.php file, loading class library $reader = new Spreadsheet_excel_reader (); Instantiate analytic class spreadsheet_excel_reader$reader->setoutputencoding ("CP1251"); Set the encoding mode $reader->read ("Jxlwtest.xls"); Read and parse the file (Jxlwtest.xls as file name)
After the completion of the four-sentence code, the Excel file is parsed. The result of parsing is in array $reader->sheets[0], contains MaxRow, Maxcol, NumRows, numcols, cells, cellsinfo six items, which are useful numrows (number of rows), Numcols (Number of columns) , cells (cell contents). To get the specific data information for an Excel file, iterate through the $reader->sheets[0]["cells" array. The array is shaped like
$reader->sheets[0]["Cells"][< row index >][< Column index = < value in Cell >
Two-dimensional array, row and column indexes are counted starting at 1.
What needs to be stated is:
The Oleread.inc file has been included with require_once in the 1.excel/reader.php file, so there is no need to load oleread.inc at the time of the call.
2. The official Excel file Jxlwtest.xls has been corrupted and cannot be read and parsed.
3. The 31st line of the original excel/reader.php file (as follows) can cause an error:
Require_once ' spreadsheet/excel/reader/oleread.php ';
The reason is that the spreadsheet/excel/reader/oleread.php file does not exist. In fact, the required file here is Excel/oleread.inc, the require_once after the filename changed to ' oleread.inc ' can be.
4. The No. 261 line of the original excel/reader.php file causes the following warning:
Deprecated:assigning Thereturn value of new by reference is deprecated
The reason for this is that the =& symbol for this line has been discarded in PHP 5.3. Depending on the role of the symbol here, it can be changed directly to =.
5.php-excelreader does not support parsing of Excel 2007 documents, which means that an Excel file with an extension of xlsx cannot be parsed using this class library, and it is only for Excel files with the extension xls.
The 6.php-excelreader setting encoding method is based on the Iconv command, and the Setoutputencoding method's argument is the name of the character set that needs to be set. For this method to take effect it is necessary to install the iconv extension to the local PHP environment, and if the local PHP environment does not have iconv extensions, then the Php-excelreader encoding method defaults to Unicode.
7.php-excereader in the resolution of integers may be the error of accuracy, such as 58 resolution to 57.5, unexplained. What you can do is check the data after parsing, and then round (if necessary).
8.php-excelreader for blank cells in an Excel file, either skip directly to the result array, or save as 0 or "" (empty string). This article links http://www.cxybl.com/html/wlbc/Php/20130608/38516.html

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.