zoukankan      html  css  js  c++  java
  • php获取excel文件数据

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

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

     1 require __DIR__ . './PHPExcel/IOFactory.php';
     2 
     3         $PHPReader = new PHPExcel_Reader_Excel2007();
     4 
     5         //判断文件类型
     6         if (!$PHPReader->canRead($filePath)) {
     7             $PHPReader = new PHPExcel_Reader_Excel5();
     8 
     9             if (!$PHPReader->canRead($filePath)) {
    10                 echo 'no Excel';
    11                 return false;
    12             }
    13         }
    14 
    15         $PHPExcel = $PHPReader->load($filePath);
    16         /**读取excel文件中的第一个工作表*/
    17 
    18         $currentSheet = $PHPExcel->getSheet(0);
    19         /**取得最大的列号*/
    20 
    21         $allColumn = $currentSheet->getHighestColumn();
    22         /**取得一共有多少行*/
    23 
    24         $allRow = $currentSheet->getHighestRow();
    25 
    26         /**从第1行开始输出*/
    27         for ($currentRow = 1; $currentRow <= $allRow; $currentRow++) {
    28 
    29             /**从第A列开始输出*/
    30             for ($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn++) {
    31                 $val = $currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65, $currentRow)->getValue();
    32                 /**ord()将字符转为十进制数*/
    33                 $date[$currentRow - 1][] = $val;
    34             }
    35 
    36         }
    37         return $date;
  • 相关阅读:
    确定机器上装有哪些.net framework版本
    C#中的私有构造函数
    突破vs2008 RTM90天使用限制(转)
    圣诞晚会串词(转)
    C#中ref和out
    登缙云山随笔
    质量百分百
    自然界五种长有人脸像的怪异生物
    C# 静态构造函数
    NET环境下基于Ajax的MVC方案
  • 原文地址:https://www.cnblogs.com/fwqblogs/p/6740052.html
Copyright © 2011-2022 走看看