php生成EXCEL的东东
程序员文章站
2022-04-08 23:31:58
可以通过php来产生excel档. teaman翻译 ---------------------------- excel functions --...
可以通过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
?>
----------------------------
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
?>
上一篇: php防注