当前位置: 首页 > 图文教程 > 网络编程 > PHP > php生成EXCEL的东东

PHP
一个用于网络的工具函数库
针对初学PHP者的疑难问答(1)
在PHP中执行系统外部命令
怎样在php中使用PDF文档功能
怎样在PHP中通过ADO调用Asscess数据库和COM程序
截获网站title标签之家内容的例子
如何跨站抓取别的站点的页面的补充
PHP 存取 MySQL 数据库的一个例子
PHP用户指南-cookies部分
PHP中一个控制字符串输出的函数
将OICQ数据转成MYSQL数据
在线增减.htpasswd内的用户
PHP实现图片简单上传
从C/C++迁移到PHP——判断字符类型的函数
PHP+APACHE实现用户论证的方法
vBulletin HACK----关于排版的两个HACK
PHP3 safe_mode 失效漏洞
一个改进的UBB类
如何在PHP中进行身份认证
利用递归把多维数组转为一维数组的函数

PHP 中的 php生成EXCEL的东东


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 46 ::
收藏到网摘: n/a

可以通过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
?>