楼主还是看看手册
XSL functions这一节吧读取xsl(excel)数据/*Here is function to read from the XSL sheet which is saved as a text file.*/
function ReadExcelSheet($filename){
$test=file($filename);
$ar1=str_replace("~[^\t]*\t","\t",$test);
$ar2=str_replace("~","",$ar1);
$ar=str_replace("","",$ar2);
$temp=array();
for ($i=0; $i<count($ar); $i++) {
if((substr($ar[$i],0,1)!= "\t")){
if($ar[$i]!=="\r\n"){
array_push($temp,$ar[$i]);
}
}
}
$name=split("\t",$temp[0]);
$ExcelList=array();
for($i=1;$i<count($temp);$i++){
$split_result=split("\t",$temp[$i]);
array_push($ExcelList,$split_result);
}
$result=insert_into_array($ExcelList,0,$name);
return($result);
} 下面是生成xsl数据并写入xsl文件的部分函数,只要声明一下头就可以了,数据就和写html一样,使用table就可以 $filename = "FlyMsgList".date("YmdHis").".xls";
header("Content-Type: application/vnd.ms-excel");
header("Accept-Ranges:bytes");
header("Content-type:charset=utf-8");
header("Content-Disposition: attachment; filename=".$filename);
header("Pragma: no-cache");
header("Expires: 0");
XSL functions这一节吧读取xsl(excel)数据/*Here is function to read from the XSL sheet which is saved as a text file.*/
function ReadExcelSheet($filename){
$test=file($filename);
$ar1=str_replace("~[^\t]*\t","\t",$test);
$ar2=str_replace("~","",$ar1);
$ar=str_replace("","",$ar2);
$temp=array();
for ($i=0; $i<count($ar); $i++) {
if((substr($ar[$i],0,1)!= "\t")){
if($ar[$i]!=="\r\n"){
array_push($temp,$ar[$i]);
}
}
}
$name=split("\t",$temp[0]);
$ExcelList=array();
for($i=1;$i<count($temp);$i++){
$split_result=split("\t",$temp[$i]);
array_push($ExcelList,$split_result);
}
$result=insert_into_array($ExcelList,0,$name);
return($result);
} 下面是生成xsl数据并写入xsl文件的部分函数,只要声明一下头就可以了,数据就和写html一样,使用table就可以 $filename = "FlyMsgList".date("YmdHis").".xls";
header("Content-Type: application/vnd.ms-excel");
header("Accept-Ranges:bytes");
header("Content-type:charset=utf-8");
header("Content-Disposition: attachment; filename=".$filename);
header("Pragma: no-cache");
header("Expires: 0");
如果想生成excel2007格式的文档,可以参考emca367标准,xlsx文件是个zip压缩包,你可以用php的zip来压缩打包,里面的文件内容,你需要自己维护。pear上有一个现成的输出excel类。
xlsWriteLabel的三个参数分别代表行,列,内容,每写一条,行加一,可以用$xlsRow代表行,在循环内部$xlsRow++;
上面的filename是保存EXCEL格式后的EXCEL名
<?php
function ReadExcelSheet($filename){
$test=file($filename);
$ar1=str_replace("~[^\t]*\t","\t",$test);
$ar2=str_replace("~","",$ar1);
$ar=str_replace("","",$ar2);
$temp=array();
for ($i=0; $i<count($ar); $i++) {
if((substr($ar[$i],0,1)!= "\t")){
if($ar[$i]!=="\r\n"){
array_push($temp,$ar[$i]);
}
}
}
$name=split("\t",$temp[0]);
$ExcelList=array();
for($i=1;$i<count($temp);$i++){
$split_result=split("\t",$temp[$i]);
array_push($ExcelList,$split_result);
}
$result=insert_into_array($ExcelList,0,$name);
return($result);
}
function insert_into_array($array,$ky,$val)
{
$n = $ky;
foreach($array as $key => $value)
{
$backup_array[$key] = $array[$key];
}
$upper_limit = count($array);
while($n <= $upper_limit)
{
if($n == $ky)
{
$array[$n] = $val;
echo $n;
}
else
{
$i = $n - "1";
$array[$n] = $backup_array[$i];
}
$n++;
}
return $array;
} $aa = ReadExcelSheet('sta.xls');
var_dump($aa);
?>
这个我测试成功了
为什么说不能读取呢,而且还那么多人跟风,就因为2楼的朋友级别高吗 是专家吗,要知道没有实践就没有发言权
http://k0102.bokee.com/viewdiary.36133674.html
http://pear.php.net/package/Spreadsheet_Excel_Writer读
http://code.google.com/p/php-excel-reader/