zl程序教程

您现在的位置是:首页 >  工具

当前栏目

php生成EXCEL的东东

ExcelPHP 生成 东东
2023-06-13 09:13:44 时间
可以通过PHP来产生EXCEL档.  teaman翻译
----------------------------
ExcelFunctions
----------------------------
将下面的代码存为excel.php,然后在页面中包括进来

然后调用
1.CallxlsBOF()  
2.将一些内容写入到xlswritenunber()或者xlswritelabel()中.
3.然后调用CallxlsEOF()

也可以用fwrite函数直接写到服务器上,而不是用echo仅仅在浏览器上显示。



<?php
//-----beginoffunctionlibrary-----
//Excelbeginoffileheader
functionxlsBOF(){
    echopack("ssssss",0x809,0x8,0x0,0x10,0x0,0x0);  
    return;
}
//Excelendoffilefooter
functionxlsEOF(){
    echopack("ss",0x0A,0x00);
    return;
}
//FunctiontowriteaNumber(double)intoRow,Col
functionxlsWriteNumber($Row,$Col,$Value){
    echopack("sssss",0x203,14,$Row,$Col,0x0);
    echopack("d",$Value);
    return;
}
//Functiontowritealabel(text)intoRow,Col
functionxlsWriteLabel($Row,$Col,$Value){
    $L=strlen($Value);
    echopack("ssssss",0x204,8+$L,$Row,$Col,0x0,$L);
    echo$Value;
return;
}
//-----endoffunctionlibrary-----
?>

//  
//TodisplaythecontentsdirectlyinaMIMEcompatiblebrowser  
//addthefollowinglinesonTOPofyourPHPfile:

<?php
header("Expires:Mon,26Jul199705:00:00GMT");
header("Last-Modified:".gmdate("D,dMYH:i:s")."GMT");
header("Cache-Control:no-cache,must-revalidate");     
header("Pragma:no-cache");     
header("Content-type:application/x-msexcel");
header("Content-Disposition:attachment;filename=EmplList.xls");  
header("Content-Description:PHP/INTERBASEGeneratedData");
//
//thenextlinesdemonstratethegenerationoftheExcelstream
//
xlsBOF();   //beginExcelstream
xlsWriteLabel(0,0,"Thisisalabel");  //writealabelinA1,usefordatestoo
xlsWriteNumber(0,1,9999);  //writeanumberB1
xlsEOF();//closethestream
?>