这篇文章主要为大家详细介绍了PHPExcel 读取EXECL简单示例,具有一定的参考价值,可以用来参考一下。
对phpPHPExcel 读取EXECL简单示例感兴趣的小伙伴,下面一起跟随四海网的小编巴闭妹来看看吧!
/**
*
* @param
* @arrange (512.笔记) www.q1010.com
**/
require_once('./excel/Classes/PHPExcel.php');
//require_once('./excel/Classes/PHPExcel/IOFactory.php');
$inputFileName = './xls/a.xls';
function readxls($inputFileName){
$objReader = new PHPExcel_Reader_Excel5();
$objPHPExcel = $objReader->load($inputFileName);
//print_r($objPHPExcel);
$tmp = array();
$objWorksheet = $objPHPExcel->getActiveSheet();
$i = 0;
foreach($objWorksheet->getRowIterator() as $row){
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);
foreach($cellIterator as $cell){
$tmp[$i][] = $cell->getValue();
}
$i++;
}
return $tmp;
}
$con = readxls($inputFileName);
print_r($con);
版本2:
function readxls($inputFileName){
require_once('/www/web/wwwroot/public_html/system/plugins/PHPExcel/PHPExcel.php');
$type = strtolower( pathinfo($inputFileName, PATHINFO_EXTENSION) );
if (!file_exists($inputFileName)) {
die('no file!');
}
//根据不同类型分别操作
if( $type=='xlsx'||$type=='xls' ){
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
}else if( $type=='csv' ){
$objReader = PHPExcel_IOFactory::createReader('CSV')
->setDelimiter(',')
->setInputEncoding('GBK') //不设置将导致中文列内容返回boolean(false)或乱码
->setEnclosure('"')
->setLineEnding("\r\n")
->setSheetIndex(0);
$objPHPExcel = $objReader->load($path);
}else{
die('Not supported file types!');
}
$tmp = array();
$objWorksheet = $objPHPExcel->getActiveSheet();
$i = 0;
foreach($objWorksheet->getRowIterator() as $row){
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);
foreach($cellIterator as $cell){
$tmp[$i][] = $cell->getValue();
}
$i++;
}
return $tmp;
}
本文来自:http://www.q1010.com/173/11086-0.html
注:关于PHPExcel 读取EXECL简单示例的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。
关键词:
四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。