php有个PHPExcel扩展,是可以实现你的要求的。
我这里有个可以读取多个工作薄的自定义excel类,试试看:
/**
*excel.class.php
*/
classExcel
{
/**
*从excel文件中取得所有数据。并转换成指定编码格式。
*$toCode表示需要转换成的编码格式,目前扩充了utf8,gbk2312,html三种格式。
*@return返回二维数组。
*/
staticfunctiongetDataFromExl($filePath,$toCode="utf8")
{
$fh=@fopen($filePath,'rb');
if(!$fh||filesize($filePath)==0)
{
return-1;//文件不可读或者为空
}
$fc=fread($fh,filesize($filePath));
@fclose($fh);
if(strlen($fc)
{
return-2;//读取错误
}
$exc=newExcelFileParser();
$res=$exc->ParseFromString($fc);
$ws_number=count($exc->worksheet['name']);//取得工作薄数量
if($ws_number
{
return-3;
}
for($ws_n=0;$ws_n
{
$ws=$exc->worksheet['data'][$ws_n];
$data=$ws['cell'];
foreach($dataas$k=>$v)//一行数据
{
$row=null;
foreach($vas$a=>$d)//一行数据的一个字节
{
$value=null;
if(count($d)==1)
{
continue;
}
if($d['type']==0)//如果是字符类型则转换成为指定编码格式
{
$ind=$d['data'];
if($exc->sst['unicode'][$ind])//返回数据编码格式
{
switch($toCode)
{
case"utf8":
$s=Strings::uc2utf8($exc->sst['data'][$ind]);
break;
case"gbk":
$s=Strings::uc2gbk($exc->sst['data'][$ind]);
break;
case"html":
$s=Strings::uc2html($exc->sst['data'][$ind]);
break;
default:
$s=Strings::uc2utf8($exc->sst['data'][$ind]);
break;
}
}
else
{
$s=$exc->sst['data'][$ind];
}
if(strlen(trim($s))==0||$s===null)
{
$value='';
}
else
{
$value=$s;
}
}
elseif($d['type']==3)
{
$time_list=explode('.',$d['data']);
$time_format=$time_list[2].'-'.$time_list[0].'-'.$time_list[1];
$timestamp=strtotime($time_format);
$value=date("Y-m-dH:i:s",$timestamp);
}
else
{
$value=$d['data'];
}
$row[$a]=$value;
}
$recordList[]=$row;
}
}
return$recordList;
}
}
require_once('./excel.class.php');
$emailData=Excel::getDataFromExl($_FILES['file_name']['tmp_name']);