Phpexcel reading XLS files
There are many ways to read an XLS file, and one can be mastered. I use the Phpexcel class, there is a little I also wonder, download down the file is quite large, even according to Netizens said as long as [img][/img], is also very big, enough 18M, below we see Phpexcel is how to read the XLS file.
PHP code?
- require ? ' excel/phpexcel.php ' ;? //Load file ??
- ?? $filename = "D:/wamp/www/test/sysoa.xls" ; ??
- ? //Read 2003 and previous versions of XLS files ??
- $phpreader = New ? Phpexcel_reader_excel5 ();??
- if ($phpreader->canread ($filename)) {??
- ??
- ???? $excel = $phpreader ->load ($filename);? ?
- ???? //Get current worksheet ??
- ?? ??
- ???? $cursheet = $excel ->getsheet (0);??
- ???? ///How many columns are obtained, and if you do not use this static method, the $col is the largest English capital letter of the file column ??
- ???? $col =phpexcel_cell::columnindexfromstring ($cursheet->gethighestcolumn ());??
- ???? ??
- ???? //How many lines are obtained ??
- ???? $row = $cursheet ->gethighestrow ();??
- ??
- ???? ///loop fetch data, XLS file is listed on the first row after the second column, in fact, the XLS is expressed as B2 ??
- ??
- ???? for ($currow=1; $currow <= $row ; $currow ++) { ??
- ?????? for ($curcol=1; $curcol <= $col ; $curcol ++) { ??
- ??????????? $result = $cursheet ->getcellbycolumnandrow ($curcol,$currow)->getvalue ();? ?
- ??????????? if ($result) {??
- ??????????? Echo ? ' first ' . $currow . ' line ' . $curcol . ' column: ' . $result . ' ' ; ??
- ???????????} ??
- ??????} ??
- ?????? Echo ? '
'; ??
- ????} ??
- ????? ??
- }??
Require ' excel/phpexcel.php '; Load file $filename = "D:/wamp/www/test/sysoa.xls"; Read 2003 and previous versions of the XLS file $phpreader =new phpexcel_reader_excel5 (); if ($phpreader->canread ($filename)) { $excel = $phpreader->load ($filename); Get current worksheet $cursheet = $excel->getsheet (0); How many columns are obtained, and if you do not use this static method, the $col is the largest uppercase letter of the file column $col =phpexcel_cell::columnindexfromstring ($cursheet Gethighestcolumn ()); The total number of lines obtained $row = $cursheet->gethighestrow (); Loop fetch data, XLS file is listed on the first row after the second column, in fact, XLS is expressed in B2 for ($currow =1; $currow <= $row; $currow + +) {for ($curcol = 1; $curcol <= $col; $curcol + +) { $result = $cursheet->getcellbycolumnandrow ($curcol, $currow)->getvalue ( ); if ($result) { echo '. $currow. ' line '. $curcol. ' column: '. $result. ' ; } } Echo '
'; } }
? However, there are still some problems not resolved, I read another xls file, $row = $cursheet->gethighestrow (); The value is 65522, it's really puzzling, but it's good to change.
1/F pz9042 2012-06-06
。。。 This is what I wrote.