mot
  • 1.2k

使用PHPExcel读取xls/xlsx文件

 阅读约 3 分钟

需要第三方的库 phpexcel

require_once( LIB.'Excel/excel/PHPExcel/IOFactory.php');

function readexcel( $filePath) {
$PHPReader = new PHPExcel_Reader_Excel5();
         if(!$PHPReader->canRead($filePath)){   
             $PHPReader = new PHPExcel_Reader_Excel5();   
                   if(!$PHPReader->canRead($filePath)){         
                        echo 'no Excel';  
                         return ;   
                   }  
          }

$PHPExcel = $PHPReader->load($filePath);  

$currentSheet = $PHPExcel->getSheet(0);  /**取得一共有多少列*/

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

$allRow = $currentSheet->getHighestRow();

$all = array();
for( $currentRow = 1 ; $currentRow <= $allRow ; $currentRow++){

          $flag = 0;
          $col = array();
          for($currentColumn='A'; getascii($currentColumn) <= getascii($allColumn) ; $currentColumn++){

                $address = $currentColumn.$currentRow;   

                $string = $currentSheet->getCell($address)->getValue();

                $col[$flag] = $string;

                $flag++;
          }
      $all[] = $col;
}
return $all;
}
阅读 5k发布于 2014-01-08
推荐阅读
404 Page Not Found
用户专栏

if (is.ie) { window.location.href="config/error.htm"; }

4 人关注
45 篇文章
专栏主页
目录