PHP Development will certainly encounter the need to import Excel file content into the database, Php-excel-reader is a class that reads Excel, it is easy to use it to read Excel files very convenient.
Php-excel-reader Download Address: http://www.php.net/codes/67223.html
I downloaded the php-excel-reader-2.21 version, the use of the time also encountered a few small problems, and then elaborate on the first instance of PHP:
I use Excel such as:
The PHP code is as follows:
Copy the Code code as follows:
/*by www.phpddt.com*/
Header ("Content-type:text/html;charset=utf-8");
Require_once ' excel_reader2.php ';
Creating objects
$data = new Spreadsheet_excel_reader ();
Set the text output encoding
$data->setoutputencoding (' UTF-8 ');
Reading Excel files
$data->read ("Example.xls");
$data->sheets[0][' NumRows ') is the number of lines in Excel
for ($i = 1; $i <= $data->sheets[0][' numrows '); $i + +) {
$data->sheets[0][' Numcols ') is the number of Excel columns
for ($j = 1; $j <= $data->sheets[0][' numcols '); $j + +) {
Show each cell contents
echo $data->sheets[0][' cells ' [$i] [$j]. ' ';
}
Echo '
';
}
?>
The results read as follows :
Again, the small problem with this class:
(1) appears deprecated:function split () is deprecated in ... Error
Solution: Will excel_reader2.php source split to explode, details click PHP explode and split the difference introduced
(2) Deprecated:assigning The return value of the new by reference was deprecated in error
Solution: The excel_reader2.php source code in $this->_ole =& new Oleread () & Remove, because php5.3 in the abolition of the =& symbol directly with the = reference
(3) Garbled problem solving:
The constructor is a function spreadsheet_excel_reader ($file = ', $store _extended_info=true, $outputEncoding = '), and its default encoding is Utf-8, If not specified, garbled problems can occur through $data->setoutputencoding (' GBK '); specify, and if you use the dump () function, the dump () function will output the Excel content in HTML format, Using Htmlentities to convert characters to HTML, it uses ISO8559-1 encoding by default, so you'll change the htmlentities ($val) function in excel_reader2.php source to Htmlentities ($val, Ent_compat, "GB2312");
to conclude, Php-excel-reader operates two important methods in Excel :
1.dump (), which can output Excel content in HTML format:
echo $data->dump (true,true);
2. Save the Excel data in an array, using $data->sheets, print as follows:
Copy CodeThe code is as follows:
Array
(
[0] = = Array
(
[MaxRow] = 0
[Maxcol] = 0
[NumRows] = 5
[Numcols] = 4
[Cells] = Array
(
[1] = = Array
(
[1] = = number
[2] = name
[3] = Age
[4] = = Study No.
)
[2] = = Array
(
[1] = 1
[2] = red
[3] = 22
[4] = A1000
)
[3] = = Array
(
[1] = 2
[2] = Xiao Wang
[3] = 33
[4] = a1001
)
[4] = = Array
(
[1] = 3
[2] = small Black
[3] = 44
[4] = a1002
)
[5] = = Array
(
[2] = by
[3] = www.phpddt.com
)
)
[Cellsinfo] = = Array
(
[1] = = Array
(
[1] = = Array
(
[Xfindex] = 15
)
[2] = = Array
(
[Xfindex] = 15
)
[3] = = Array
(
[Xfindex] = 15
)
[4] = = Array
(
[Xfindex] = 15
)
)
[2] = = Array
(
[1] = = Array
(
[String] = 1
[Raw] = 1
[RecType] = unknown
[Format] =%s
[Formatindex] = 0
[Fontindex] = 0
[FormatColor] =
[Xfindex] = 15
)
[2] = = Array
(
[Xfindex] = 15
)
[3] = = Array
(
[string] = 22
[Raw] = 22
[RecType] = unknown
[Format] =%s
[Formatindex] = 0
[Fontindex] = 0
[FormatColor] =
[Xfindex] = 15
)
[4] = = Array
(
[Xfindex] = 15
)
)
[3] = = Array
(
[1] = = Array
(
[String] = 2
[Raw] = 2
[RecType] = unknown
[Format] =%s
[Formatindex] = 0
[Fontindex] = 6
[FormatColor] =
[Xfindex] = 23
)
[2] = = Array
(
[Xfindex] = 23
)
[3] = = Array
(
[String] = 33
[Raw] = 33
[RecType] = unknown
[Format] =%s
[Formatindex] = 0
[Fontindex] = 6
[FormatColor] =
[Xfindex] = 23
)
[4] = = Array
(
[Xfindex] = 23
)
)
[4] = = Array
(
[1] = = Array
(
[String] = 3
[Raw] = 3
[RecType] = unknown
[Format] =%s
[Formatindex] = 0
[Fontindex] = 0
[FormatColor] =
[Xfindex] = 15
)
[2] = = Array
(
[Xfindex] = 15
)
[3] = = Array
(
[String] = 44
[Raw] = 44
[RecType] = unknown
[Format] =%s
[Formatindex] = 0
[Fontindex] = 0
[FormatColor] =
[Xfindex] = 15
)
[4] = = Array
(
[Xfindex] = 15
)
)
[5] = = Array
(
[2] = = Array
(
[Xfindex] = 15
)
[3] = = Array
(
[Xfindex] = 24
[Hyperlink] = = Array
(
[Flags] = 23
[DESC] = www.phpddt.com
[link] = http://www.phpddt.co
)
)
)
)
)
[1] = = Array
(
[MaxRow] = 0
[Maxcol] = 0
[NumRows] = 0
[Numcols] = 0
)
[2] = = Array
(
[MaxRow] = 0
[Maxcol] = 0
[NumRows] = 0
[Numcols] = 0
)
)
So you should know how to get the data in Excel, well, it's so easy to read an Excel file using Php-excel-reader