设为首页 - 加入收藏 ASP站长网(Aspzz.Cn)- 科技、建站、经验、云计算、5G、大数据,站长网!
热搜: 创业者 手机 数据
当前位置: 首页 > 站长学院 > PHP教程 > 正文

PHPEXCEL导入excel表格产生数组

发布时间:2022-02-10 14:38 所属栏目:121 来源:互联网
导读:本方法使用PHPEXCEL插件读取excel文件转化为数组了,后期还有没有完成的我们可以把转换成数组之后再保存到mysql数据库这个就非常的方便了,代码如下: ?php /** * @desc PHPEXCEL导入 * return array(); */ function importExcel($file) { require_once PHPExce
  本方法使用PHPEXCEL插件读取excel文件转化为数组了,后期还有没有完成的我们可以把转换成数组之后再保存到mysql数据库这个就非常的方便了,代码如下:
 
  <?php
  /**
   * @desc PHPEXCEL导入
   * return array();
   */
  function importExcel($file)
  {
      require_once 'PHPExcel.php';
      require_once 'PHPExcel/IOFactory.php';
      require_once 'PHPExcel/Reader/Excel5.php';
      $objReader = PHPExcel_IOFactory::createReader('Excel5');//use excel2007 for 2007 format
      $objPHPExcel = $objReader->load($file);
      $sheet = $objPHPExcel->getSheet(0);
      $highestRow = $sheet->getHighestRow(); // 取得总行数
      $highestColumn = $sheet->getHighestColumn(); // 取得总列数
      $objWorksheet = $objPHPExcel->getActiveSheet();
  
      $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
      $excelData = array();
      for ($row = 1; $row <= $highestRow; $row++) {
          for ($col = 0; $col < $highestColumnIndex; $col++) {
              $excelData[$row][] =(string)$objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
          }
      }
      return $excelData;
  }
  //用法:
  importExcel('test.xsl');
  //开源代码Cuoxin.com
  ?> 

(编辑:ASP站长网)

    网友评论
    推荐文章
      热点阅读