Use phpexcel to read xls documents

Source: Internet
Author: User
Phpexcel provides many methods to read xls files. I am using the phpexcel class. I am also wondering that the downloaded files are quite large, even if [img] [img] is what netizens say, the size is 18 MB. let's see how phpexcel reads xls files. Php code? Require? ExcelPHPExcel. php ;? Add phpexcel to read xls files

There are many ways to read xls files. we can master one of them. I am using the phpexcel class, and I am also wondering that the downloaded files are quite large, even if [img] [/img] is what netizens say, the size is 18 MB. let's see how phpexcel reads xls files.

Php code?

  1. Require? 'Excel/PHPExcel. php ';? // Load the file ??
  2. ?? $ Filename = "D:/wamp/www/test/sysoa.xls ";??
  3. ? // Read the xls files of Version 2003 and earlier versions ??
  4. $ Phpreader =New? PHPExcel_Reader_Excel5 ();??
  5. If($ Phpreader-> canRead ($ filename )){??
  6. ??
  7. ???? $ Excel = $ phpreader-> load ($ filename );??
  8. ???? // Get the current worksheet ??
  9. ?? ??
  10. ???? $ Cursheet = $ excel-> getSheet (0 );??
  11. ???? // How many columns are obtained. if this static method is not used, the obtained $ col is the maximum uppercase letter of the file column ??
  12. ???? $ Col = PHPExcel_Cell: columnIndexFromString ($ cursheet-> getHighestColumn ());??
  13. ???? ??
  14. ???? // How many rows are obtained ??
  15. ???? $ Row = $ cursheet-> getHighestRow ();??
  16. ??
  17. ???? // Obtain data cyclically. The xls file is expressed in 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? 'Column '. $ currow.' Row '. $ curcol.': '. $ result .'';??
  24. ???????????} ??
  25. ??????} ??
  26. ?????? Echo? '
    ';??
  27. ????} ??
  28. ????? ??
  29. }??

Require 'Excel/PHPExcel. php '; // load the file $ filename = "D:/wamp/www/test/sysoa.xls "; // read the xls files of Version 2003 and earlier $ phpreader = new PHPExcel_Reader_Excel5 (); if ($ phpreader-> canRead ($ filename )) {$ excel = $ phpreader-> load ($ filename); // Obtain the current worksheet $ cursheet = $ excel-> getSheet (0); // obtain the total number of columns, if you do not use this static method, the obtained $ col is the largest capital letter in the file column $ col = PHPExcel_Cell: columnIndexFromString ($ cursheet-> getHighestColumn ()); // obtain the total number of rows $ row = $ cursheet-> getHighestRow (); // Obtain data cyclically. The xls file is a column after it is placed forward, such as the second column in the first row, 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 'did '. $ currow. 'row name '. $ curcol. 'column :'. $ result. '';} echo'
';}}

? But there are still some problems that have not been solved. when I read another xls file, $ row = $ cursheet-> getHighestRow (); actually got 65522, which is really confusing, but the other one is better.

1 floor 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.