用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - php代码库

PHPExcel 读取EXECL

2015-10-22 作者: fw325举报

[php]代码库

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;
}


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...