phpexcel怎么读取excel文件?phpexcel读取xls文件的例子

php中文网
发布: 2016-07-25 08:51:37
原创
1407人浏览过
  1. error_reporting(E_ALL);
  2. date_default_timezone_set('Asia/ShangHai');
  3. /** PHPExcel_IOFactory */
  4. require_once '../Classes/PHPExcel/IOFactory.php';
  5. // Check prerequisites
  6. if (!file_exists("31excel5.xls")) {
  7. exit("not found 31excel5.xls.\n");
  8. }
  9. $reader = PHPExcel_IOFactory::createReader('Excel5'); //设置以Excel5格式(Excel97-2003工作簿)
  10. $PHPExcel = $reader->load("31excel5.xls"); // 载入excel文件
  11. $sheet = $PHPExcel->getSheet(0); // 读取第一個工作表
  12. $highestRow = $sheet->getHighestRow(); // 取得总行数
  13. $highestColumm = $sheet->getHighestColumn(); // 取得总列数
  14. $highestColumm= PHPExcel_Cell::columnIndexFromString($colsNum); //字母列转换为数字列 如:AA变为27
  15. /** 循环读取每个单元格的数据 */
  16. for ($row = 1; $row for ($column = 0; $column $columnName = PHPExcel_Cell::stringFromColumnIndex($column);
  17. echo $columnName.$row.":".$sheet->getCellByColumnAndRow($column, $row)->getValue()."
    ";
  18. }
  19. }
  20. ?>
复制代码

例2,简化后的读取excel文件的方法

  1. error_reporting(E_ALL);
  2. date_default_timezone_set('Asia/ShangHai');
  3. /** PHPExcel_IOFactory */
  4. require_once '../Classes/PHPExcel/IOFactory.php';
  5. // Check prerequisites
  6. if (!file_exists("31excel5.xls")) {
  7. exit("not found 31excel5.xls.\n");
  8. }
  9. $reader = PHPExcel_IOFactory::createReader('Excel5'); //设置以Excel5格式(Excel97-2003工作簿)
  10. $PHPExcel = $reader->load("31excel5.xls"); // 载入excel文件
  11. $sheet = $PHPExcel->getSheet(0); // 读取第一個工作表
  12. $highestRow = $sheet->getHighestRow(); // 取得总行数
  13. $highestColumm = $sheet->getHighestColumn(); // 取得总列数
  14. /** 循环读取每个单元格的数据 */
  15. for ($row = 1; $row for ($column = 'A'; $column $dataset[] = $sheet->getCell($column.$row)->getValue();
  16. echo $column.$row.":".$sheet->getCell($column.$row)->getValue()."
    ";
  17. }
  18. }
  19. ?>
复制代码


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

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

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

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