PHPExcel读取Excel2007



 

<?php
  header("Content-Type:text/html;charset=utf-8");
  // ini_set('memory_limit','200M');                          //设置文件上传大小
  require_once 'PHPExcel.php';
  require_once 'PHPExcel/IOFactory.php';
  $reader = PHPExcel_IOFactory::createReader('Excel2007');  //  读取 excel 文件方式  此方法是读取excel2007之前的版本 excel2007 为读取2007以后的版本 也可以查\Classes\PHPExcel\Reader 文件夹中的类(为所有读取类,需要哪个填上哪个就行)
  $resource = 'test.xlsx';
  if (! file_exists( $resource)) {
   exit(" $resource is not exists.\n");
 }




  $PHPExcel =  $reader->load("test.xlsx");  //  文件名称
  $sheet =  $PHPExcel->getSheet(0);  //  读取第一个工作表从0读起
  $highestRow =  $sheet->getHighestRow();  //  取得总行数
  $highestColumn =  $sheet->getHighestColumn();  //  取得总列数
  echo  $highestRow. $highestColumn;
  //  根据自己的数据表的大小修改
  $arr =  array(1=>'A',2=>'B',3=>'C',4=>'D',5=>'E',6=>'F',7=>'G',8=>'H',9=>'I',10=>'J',11=>'K',12=>'L',13=>'M', 14=>'N',15=>'O',16=>'P',17=>'Q',18=>'R',19=>'S',20=>'T',21=>'U',22=>'V',23=>'W',24=>'X',25=>'Y',26=>'Z');
 
  //  每次读取一行,再在行中循环每列的数值
  for ( $row = 1;  $row <=  $highestRow$row++) {
   for ( $column = 1;  $arr[ $column] != 'D';  $column++) {
    $val =  $sheet->getCellByColumnAndRow( $column$row)->getValue();
    $list[ $row][] =  $val;
  }
 }
  echo "<pre>". print_r( $list)."</pre>";

?>

 

 转自 http://yuninglovekefan.blog.sohu.com/169872265.html


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM