phpexcel類庫讀取excel檔案的例子

來源:互聯網
上載者:User
  1. require_once('include/common.inc.php');
  2. require_once(rootpath . 'include/phpexcel/phpexcel/iofactory.php');
  3. $filepath = './file/xls/110713.xls';
  4. $filetype = phpexcel_iofactory::identify($filepath); //檔案名稱自動判斷檔案類型
  5. $objreader = phpexcel_iofactory::createreader($filetype);
  6. $objphpexcel = $objreader->load($filepath);
  7. $currentsheet = $objphpexcel->getsheet(0); //第一個活頁簿
  8. $allrow = $currentsheet->gethighestrow(); //行數
  9. $output = array();
  10. $pretype = '';
  11. #// bbs.it-home.org
  12. $qh = $currentsheet->getcell('a4')->getvalue();
  13. //按照檔案格式從第7行開始迴圈讀取資料
  14. for($currentrow = 7;$currentrow<=$allrow;$currentrow++){
  15. //判斷每一行的b列是否為有效序號,如果為空白或者小於之前的序號則結束
  16. $xh = (int)$currentsheet->getcell('b'.$currentrow)->getvalue();
  17. if(empty($xh))break;
  18. $tmptype = (string)$currentsheet->getcell('c'.$currentrow)->getvalue(); //賽事類型
  19. if(!empty($tmptype))$pretype = $tmptype;
  20. $output[$xh]['type'] = $pretype;
  21. $output[$xh]['master'] = $currentsheet->getcell('f'.$currentrow)->getvalue(); //主隊
  22. $output[$xh]['guest'] = $currentsheet->getcell('h'.$currentrow)->getvalue(); //客隊
  23. }
  24. //從當前行開始往下迴圈,取出第一個不為空白的行
  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 '期號:' . $qh . "\n\n";
  36. if(!empty($output)){
  37. printf("%-5s\t%-15s\t%-40s\t%-40s\t%-5s\n", '序號', '賽事類型', '主隊', '客隊', '讓球值');
  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. ?>
複製代碼
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.