首页 编程教程正文

php生成EXCEL的东东

piaodoo 编程教程 2020-02-02 13:49:58 879 0 php教程

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

版权声明:

本站所有资源均为站长或网友整理自互联网或站长购买自互联网,站长无法分辨资源版权出自何处,所以不承担任何版权以及其他问题带来的法律责任,如有侵权或者其他问题请联系站长删除!站长QQ754403226 谢谢。

有关影视版权:本站只供百度云网盘资源,版权均属于影片公司所有,请在下载后24小时删除,切勿用于商业用途。本站所有资源信息均从互联网搜索而来,本站不对显示的内容承担责任,如您认为本站页面信息侵犯了您的权益,请附上版权证明邮件告知【754403226@qq.com】,在收到邮件后72小时内删除。本文链接:https://www.piaodoo.com/3638.html

评论

搜索