Phpexcel Reading XLS data

Source: Internet
Author: User
Tags uppercase letter
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?

  1. require ? ' excel/phpexcel.php ' ;? //Load file ??
  2. ?? $filename = "D:/wamp/www/test/sysoa.xls" ; ??
  3. ? //Read 2003 and previous versions of XLS files ??
  4. $phpreader = New ? Phpexcel_reader_excel5 ();??
  5. if ($phpreader->canread ($filename)) {??
  6. ??
  7. ???? $excel = $phpreader ->load ($filename);? ?
  8. ???? //Get current worksheet ??
  9. ?? ??
  10. ???? $cursheet = $excel ->getsheet (0);??
  11. ???? ///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 ??
  12. ???? $col =phpexcel_cell::columnindexfromstring ($cursheet->gethighestcolumn ());??
  13. ???? ??
  14. ???? //How many lines are obtained ??
  15. ???? $row = $cursheet ->gethighestrow ();??
  16. ??
  17. ???? ///loop fetch data, XLS file is listed on the first row after the second column, in fact, the XLS is expressed as B2 ??
  18. ??
  19. ???? for ($currow=1; $currow <= $row ; $currow ++) { ??
  20. ?????? for ($curcol=1; $curcol <= $col ; $curcol ++) { ??
  21. ??????????? $result = $cursheet ->getcellbycolumnandrow ($curcol,$currow)->getvalue ();? ?
  22. ??????????? if ($result) {??
  23. ??????????? Echo ? ' first ' . $currow . ' line ' . $curcol . ' column: ' . $result . ' ' ; ??
  24. ???????????} ??
  25. ??????} ??
  26. ?????? Echo ? '
    '; ??
  27. ????} ??
  28. ????? ??
  29. }??

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.

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