php读取excel的数据,php读取excel文件数据
require_once $_SERVER[‘DOCUMENT_ROOT‘].‘/Classes/PHPExcel.php‘;
require_once $_SERVER[‘DOCUMENT_ROOT‘].‘/Classes/PHPExcel/IOFactory.php‘;
function getReadExcel($uploadfile,$time){
$extension = substr($uploadfile,strrpos($uploadfile,‘.‘)+1);
switch ($extension){
case ‘xlsx‘:{
$objReader = PHPExcel_IOFactory::createReader(‘Excel2007‘);/*excel2007 for 2007*/
}break;
case ‘xls‘:{
$objReader = PHPExcel_IOFactory::createReader(‘Excel5‘);/*Excel5 for 2003*/
}break;
case ‘csv‘:{
$objReader = PHPExcel_IOFactory::createReader(‘CSV‘);/*Csv for csv*/
}break;
}
$objPHPExcel = $objReader->load($uploadfile); //Excel 路徑
$sheet = $objPHPExcel->getSheet(0);
$objWorksheet = $objPHPExcel->getActiveSheet();
$highestRow = $sheet->getHighestRow(); // 取得總行數(shù)
$highestColumn = $sheet->getHighestColumn(); // 取得總列數(shù)
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);//總列數(shù)
for ($row = 1;$row <= $highestRow;$row++){
$strs=array();
//注意highestColumnIndex的列數(shù)索引從0開始
for ($col = 0;$col < $highestColumnIndex;$col++){
$strs[$col] = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
if($extension == ‘csv‘){
$strs[$col] = iconv(‘gbk‘, ‘utf-8‘, $strs[$col]);
}
}
$data[] = $strs;
}
return $data;
}
原文:http://www.cnblogs.com/yuwenbo/p/7047182.html
總結(jié)
以上是生活随笔為你收集整理的php读取excel的数据,php读取excel文件数据的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: hive中如何把13位转化为时间_重要知
- 下一篇: ios时间相差多少天_iOS 计算某个时