首页 > 开发 > PHP > 正文

php生成EXCEL的东东

2024-05-04 23:00:48
字体:
来源:转载
供稿:网友

商业源码热门下载www.html.org.cn

可以通过php来产生excel档.  teaman翻译
----------------------------
excel functions
----------------------------
将下面的代码存为excel.php ,然后在页面中包括进来

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

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


<?php
// ----- begin of function library -----
// excel begin of file header
function xlsbof() {
    echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);  
    return;
}
// excel end of file footer
function xlseof() {
    echo pack("ss", 0x0a, 0x00);
    return;
}
// function to write a number (double) into row, col
function xlswritenumber($row, $col, $value) {
    echo pack("sssss", 0x203, 14, $row, $col, 0x0);
    echo pack("d", $value);
    return;
}
// function to write a label (text) into row, col
function xlswritelabel($row, $col, $value ) {
    $l = strlen($value);
    echo pack("ssssss", 0x204, 8 + $l, $row, $col, 0x0, $l);
    echo $value;
return;
}
// ----- end of function library -----
?>

//  
// to display the contents directly in a mime compatible browser  
// add the following lines on top of your php file:

<?php
header ("expires: mon, 26 jul 1997 05:00:00 gmt");
header ("last-modified: " . gmdate("d,d m yh: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/interbase generated data" );
//
// the next lines demonstrate the generation of the excel stream
//
xlsbof();   // begin excel stream
xlswritelabel(0,0,"this is a label");  // write a label in a1, use for dates too
xlswritenumber(0,1,9999);  // write a number b1
xlseof(); // close the stream
?>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表