Home > Backend Development > PHP Tutorial > php import excel php use phpexcel to import excel files

php import excel php use phpexcel to import excel files

WBOY
Release: 2016-07-25 08:54:47
Original
984 people have browsed it
  1. //载入PHPExcel类

  2. include(dirname(__FILE__).'/phpexcel/PHPExcel.php');

  3. $Obj = new PHPExcel_Reader_Excel5();

  4. $Obj->setReadDataOnly(true);

  5. //读取demo.xls文件

  6. $phpExcel = $Obj->load(dirname(__FILE__).'/output.xls');

  7. //获取当前活动sheet

  8. $objWorksheet = $phpExcel->getActiveSheet();

  9. //获取行数

  10. $highestRow = $objWorksheet->getHighestRow();

  11. //获取列数

  12. //by bbs.it-home.org
  13. $highestColumn = $objWorksheet->getHighestColumn();
  14. $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);

  15. //循环输出数据

  16. $data = array();
  17. for($row = 1; $row <= $highestRow; ++$row) {
  18. for($col = 0; $col < $highestColumnIndex; ++$col) {
  19. $val = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
  20. $data[$row][$col] = trim($val);
  21. }
  22. }

  23. echo '

    ';</li>
    <li>print_r($data);</li>
    <li>echo '
    ';

复制代码


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template