phpexcel 讀取xls資料

來源:互聯網
上載者:User
phpexcel 讀取xls檔案
讀取xls檔案的方法很多,我們掌握其中一種即可。我用的是phpexcel類,有一點我也納悶,下載下來的檔案相當大,即使按網友們說的只要[img][/img],也是很大的,足有18M,下面我們看下phpexcel是如何讀取xls檔案的。
Php代碼 ?

  1. require?'excel/PHPExcel.php';?//負載檔案 ??
  2. ??$filename="D:/wamp/www/test/sysoa.xls"; ??
  3. ?//讀取2003以及之前版本的xls檔案 ??
  4. $phpreader=new?PHPExcel_Reader_Excel5(); ??
  5. if($phpreader->canRead($filename)){ ??
  6. ??
  7. ????$excel=$phpreader->load($filename); ??
  8. ????//取得當前worksheet ??
  9. ?? ??
  10. ????$cursheet=$excel->getSheet(0); ??
  11. ????//取得共有多少列,若不使用此靜態方法,獲得的$col是檔案列的最大的英文大寫字母 ??
  12. ????$col=PHPExcel_Cell::columnIndexFromString($cursheet->getHighestColumn()); ??
  13. ???? ??
  14. ????//取得共有多少行 ??
  15. ????$row=$cursheet->getHighestRow(); ??
  16. ??
  17. ????//迴圈擷取資料,xls檔案是列在前行在後比如第一行第二列,實際上xls是以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?'第'.$currow.'行第'.$curcol.'列:'.$result.' '; ??
  24. ???????????} ??
  25. ??????} ??
  26. ??????echo?'
    '; ??
  27. ????} ??
  28. ????? ??
  29. }??

 require 'excel/PHPExcel.php'; //負載檔案   $filename="D:/wamp/www/test/sysoa.xls";  //讀取2003以及之前版本的xls檔案 $phpreader=new PHPExcel_Reader_Excel5(); if($phpreader->canRead($filename)){      $excel=$phpreader->load($filename);     //取得當前worksheet        $cursheet=$excel->getSheet(0);     //取得共有多少列,若不使用此靜態方法,獲得的$col是檔案列的最大的英文大寫字母     $col=PHPExcel_Cell::columnIndexFromString($cursheet->getHighestColumn());          //取得共有多少行     $row=$cursheet->getHighestRow();     //迴圈擷取資料,xls檔案是列在前行在後比如第一行第二列,實際上xls是以B2來表達的     for($currow=1;$currow<=$row;$currow++){       for($curcol=1;$curcol<=$col;$curcol++){            $result=$cursheet->getCellByColumnAndRow($curcol,$currow)->getValue();            if($result){            echo '第'.$currow.'行第'.$curcol.'列:'.$result.'  ';            }       }       echo '
'; } }

? 不過還有一些問題沒有解決,我在讀取另外一個xls檔案時, $row=$cursheet->getHighestRow();獲得的值竟然是65522,實在讓人納悶,但換一個又好了

1 樓 pz9042 2012-06-06

。。。這是我寫的。。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.