php获取excel文件数据

yipeiwu_com6年前PHP代码库

很简单就可以实现,下面为大家简单介绍下

1、下载PHPExcel类,是一个文件夹,还得有一个文件PHPExcel.php,两个在同级目录

require __DIR__ . './PHPExcel/IOFactory.php';

  $PHPReader = new \PHPExcel_Reader_Excel2007();

  //判断文件类型
  if (!$PHPReader->canRead($filePath)) {
   $PHPReader = new \PHPExcel_Reader_Excel5();

   if (!$PHPReader->canRead($filePath)) {
    echo 'no Excel';
    return false;
   }
  }

  $PHPExcel = $PHPReader->load($filePath);
  /**读取excel文件中的第一个工作表*/

  $currentSheet = $PHPExcel->getSheet(0);
  /**取得最大的列号*/

  $allColumn = $currentSheet->getHighestColumn();
  /**取得一共有多少行*/

  $allRow = $currentSheet->getHighestRow();

  /**从第1行开始输出*/
  for ($currentRow = 1; $currentRow <= $allRow; $currentRow++) {

   /**从第A列开始输出*/
   for ($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn++) {
    $val = $currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65, $currentRow)->getValue();
    /**ord()将字符转为十进制数*/
    $date[$currentRow - 1][] = $val;
   }

  }
  return $date; 

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持【宜配屋www.yipeiwu.com】!

相关文章

谈谈从phpinfo中能获取哪些值得注意的信息

谈谈从phpinfo中能获取哪些值得注意的信息

phpinfo函数 phpinfo函数 PHP中提供了PHPInfo()函数,该函数返回 PHP 的所有信息,包括了 PHP 的编译选项及扩充配置、PHP 版本、服务器信息及环境变量、P...

Apache实现Web Server负载均衡详解(不考虑Session版)

至少需三台服务器:服务器A:控制服务器服务器B和服务器C:实际执行服务器负载均衡原理:将访问服务器A的请求分发至服务器B和服务器C修改服务器A上apache的http.conf文件: 首...

php截取视频指定帧为图片

截取视频指定帧为图片,php ffmpeg扩展已经完美实现: $movie = new ffmpeg_movie($video_filePath); $ff_frame = $mov...

PHP管理内存函数 memory_get_usage()使用介绍

下面是PHP memory_get_usage()使用示例: 复制代码 代码如下: echo memory_get_usage(), '<br />'; //143952 $...

PHP 源代码分析 Zend HashTable详解第1/3页

HashTable在通常的数据结构教材中也称作散列表,哈希表。其基本原理比较简单(如果你对其不熟悉,请查阅随便一本数据结构教材或在网上搜索),但PHP的实现有其独特的地方。理解了Hash...