phpexcel读取excel文件的二种方法

php中文网
发布: 2016-07-25 08:53:05
原创
1156人浏览过
  1. /**
  2. *
  3. * @copyright 2007-2012 xiaoqiang.
  4. * @author xiaoqiang.wu
  5. * @version 1.01
  6. */
  7. error_reporting(e_all);
  8. date_default_timezone_set('asia/shanghai');
  9. /** phpexcel_iofactory */
  10. require_once '../classes/phpexcel/iofactory.php';
  11. // check prerequisites
  12. if (!file_exists("31excel5.xls")) {
  13. exit("not found 31excel5.xls.\n");
  14. }
  15. $reader = phpexcel_iofactory::createreader('excel5'); //设置以excel5格式(excel97-2003工作簿)
  16. $phpexcel = $reader->load("31excel5.xls"); // 载入excel文件
  17. $sheet = $phpexcel->getsheet(0); // 读取第一個工作表
  18. $highestrow = $sheet->gethighestrow(); // 取得总行数
  19. $highestcolumm = $sheet->gethighestcolumn(); // 取得总列数
  20. $highestcolumm= phpexcel_cell::columnindexfromstring($colsnum); //字母列转换为数字列 如:aa变为27
  21. /** 循环读取每个单元格的数据 */
  22. for ($row = 1; $row for ($column = 0; $column $columnname = phpexcel_cell::stringfromcolumnindex($column);
  23. echo $columnname.$row.":".$sheet->getcellbycolumnandrow($column, $row)->getvalue()."
    ";
  24. }
  25. }
  26. ?>
复制代码

例2,phpexcel读取excel文件的精简方法。

  1. /**
  2. *
  3. * @copyright 2007-2012 xiaoqiang.
  4. * @author xiaoqiang.wu
  5. * @version 1.01
  6. */
  7. error_reporting(e_all);
  8. date_default_timezone_set('asia/shanghai');
  9. /** phpexcel_iofactory */
  10. require_once '../classes/phpexcel/iofactory.php';
  11. // check prerequisites
  12. if (!file_exists("31excel5.xls")) {
  13. exit("not found 31excel5.xls.\n");
  14. }
  15. $reader = phpexcel_iofactory::createreader('excel5'); //设置以excel5格式(excel97-2003工作簿)
  16. $phpexcel = $reader->load("31excel5.xls"); // 载入excel文件
  17. $sheet = $phpexcel->getsheet(0); // 读取第一個工作表
  18. $highestrow = $sheet->gethighestrow(); // 取得总行数
  19. $highestcolumm = $sheet->gethighestcolumn(); // 取得总列数
  20. /** 循环读取每个单元格的数据 */
  21. for ($row = 1; $row for ($column = 'a'; $column $dataset[] = $sheet->getcell($column.$row)->getvalue();
  22. echo $column.$row.":".$sheet->getcell($column.$row)->getvalue()."
    ";
  23. }
  24. }
  25. ?>
复制代码

以上就是phpexcel读取文件的方法与实例,phpexcel最新版下载,请访问phpexcel官网地址:http://phpexcel.codeplex.com/

小绿鲸英文文献阅读器
小绿鲸英文文献阅读器

英文文献阅读器,专注提高SCI阅读效率

小绿鲸英文文献阅读器 199
查看详情 小绿鲸英文文献阅读器


WPS零基础入门到精通全套教程!
WPS零基础入门到精通全套教程!

全网最新最细最实用WPS零基础入门到精通全套教程!带你真正掌握WPS办公! 内含Excel基础操作、函数设计、数据透视表等

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号