`
jqj031
  • 浏览: 71446 次
  • 性别: Icon_minigender_2
  • 来自: 苏州
最近访客 更多访客>>
社区版块
存档分类
最新评论

PHPExcel读取Excel文件

    博客分类:
  • php
阅读更多
$fileName = 'excel.xls';
$path = 'path';
$filePath = $path.$fileName;
$PHPExcel = new PHPExcel();  
$PHPReader = new PHPExcel_Reader_Excel2007();    
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 = array($currentSheet->getHighestRow());  

for($currentRow = 1;$currentRow<=$allRow;$currentRow++){
 for($currentColumn='A';$currentColumn<=$allColumn;$currentColumn++){
  $address = $currentColumn.$currentRow;
  
  echo $currentSheet->getCell($address)->getValue()."\t";
 }
 echo "\n";
}



分享到:
评论
2 楼 tiehao 2010-02-01  
把新增数据中文改为英文就行了 还是谢谢你的代码
1 楼 tiehao 2010-02-01  
if(!$PHPReader->canRead($filePath))
大哥我的在这里不能运行,请多指教啊
Uncaught exception 'Exception' with message 'Could not open E:\phpnow\htdocs\uniteone\新增数据.xls for reading! File does not exist.' in E:\phpnow\htdocs\test\1.7.2\Classes\PHPExcel\Reader\Excel2007.php:213 Stack trace: #0 E:\phpnow\htdocs\test\test2.php(11): PHPExcel_Reader_Excel2007->canRead('E:\phpnow\htdoc...') #1 {main} thrown in E:\phpnow\htdocs\test\1.7.2\Classes\PHPExcel\Reader\Excel2007.php on line 213

先谢谢了

相关推荐

Global site tag (gtag.js) - Google Analytics