php读取excel文件的简单实例

前端之家收集整理的这篇文章主要介绍了php读取excel文件的简单实例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

代码如下:
$this->loadexcel();//半酣PHPexcel文件
$_ReadExcel = new PHPExcel_Reader_Excel2007();
if(!$_ReadExcel->canRead('link.xls')){
$_ReadExcel = new PHPExcel_Reader_Excel5();
}
$_PHPExcel = $_ReadExcel->load('link.xls');
$sheetCount = $_PHPExcel->getSheetCount();
$newExcel = array();
$excelData = array();

for($s = 0;$s<$sheetCount;$s++) {
$currentSheet = $_PHPExcel->getSheet($s);
$allColumn = $currentSheet->getHighestColumn();
$allRow = $currentSheet->getHighestRow();
for($r = 1;$r<=$allRow;$r++){ for($currentColumn='A';$currentColumn<=$allColumn;$currentColumn++){
$address = $currentColumn.$r;
$newExcel[] = $currentSheet->getCell($address)->getValue();
}
}
}


后面就是对数组的操作了--不过要先下载好PHPexcel,并包含进来

猜你在找的PHP相关文章