Example of using the phpexcel class library to read an excel file

Source: Internet
Author: User
Example of using the phpexcel class library to read an excel file

  1. Require_once ('include/common. inc. php ');
  2. Require_once (rootpath. 'include/phpexcel/iofactory. php ');
  3. $ Filepath = './file/xls/110713.xls ';
  4. $ Filetype = phpexcel_iofactory: identify ($ filepath); // the file name automatically determines the file type.
  5. $ Objreader = phpexcel_iofactory: createreader ($ filetype );
  6. $ Objphpexcel = $ objreader-> load ($ filepath );
  7. $ Currentsheet = $ objphpexcel-> getsheet (0); // The First Workbook
  8. $ Allrow = $ currentsheet-> gethighestrow (); // number of rows
  9. $ Output = array ();
  10. $ Pretype = '';
  11. # // Bbs.it-home.org
  12. $ Qh = $ currentsheet-> getcell ('A4 ')-> getvalue ();
  13. // Read data cyclically from 7th rows according to the file format
  14. For ($ currentrow = 7; $ currentrow <= $ allrow; $ currentrow ++ ){
  15. // Determine whether column B of each row is a valid sequence number. if it is null or smaller than the previous sequence number, it ends.
  16. $ Xh = (int) $ currentsheet-> getcell ('B'. $ currentrow)-> getvalue ();
  17. If (empty ($ xh) break;
  18. $ Tmptype = (string) $ currentsheet-> getcell ('C'. $ currentrow)-> getvalue (); // event type
  19. If (! Empty ($ tmptype) $ pretype = $ tmptype;
  20. $ Output [$ xh] ['type'] = $ pretype;
  21. $ Output [$ xh] ['master'] = $ currentsheet-> getcell ('F'. $ currentrow)-> getvalue (); // lead
  22. $ Output [$ xh] ['guest '] = $ currentsheet-> getcell ('H'. $ currentrow)-> getvalue (); // The target audience
  23. }
  24. // Starts from the current row and loops down to retrieve the first non-empty row
  25. For (; $ currentrow ++ ){
  26. $ Xh = (int) $ currentsheet-> getcell ('B'. $ currentrow)-> getvalue ();
  27. If (! Empty ($ xh) break;
  28. }
  29. For (; $ currentrow <= $ allrow; $ currentrow ++ ){
  30. $ Xh = (int) $ currentsheet-> getcell ('B'. $ currentrow)-> getvalue ();
  31. If (empty ($ xh) break;
  32. $ Output [$ xh] ['rq'] = $ currentsheet-> getcell ('I'. $ currentrow)-> getvalue ();
  33. }
  34. Header ("content-type: text/html; charset = utf-8 ");
  35. Echo 'period: '. $ qh. "\ n ";
  36. If (! Empty ($ output )){
  37. Printf ("%-5s \ t %-15s \ t %-40s \ t %-40s \ t %-5s \ n", 'sequence number ', 'event type ', 'team', 'TEAM', 'Let the ball value ');
  38. Foreach ($ output as $ key => $ row ){
  39. $ Format = "%-5d \ t %-15s \ t %-40s \ t %-40s \ t %-5s \ n ";
  40. Printf ($ format, $ key, $ row ['type'], $ row ['master'], $ row ['guest '], $ row ['rq']);
  41. }
  42. }
  43. ?>

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.