php生成EXCEL的东东

2016-01-29 14:49 9 1 收藏

php生成EXCEL的东东,php生成EXCEL的东东

【 tulaoshi.com - 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
?
 

来源:http://www.tulaoshi.com/n/20160129/1494383.html

延伸阅读
标签: Web开发
如果你的服务器不容许你读他的LOG文件,那你只好停下来分析你的访问者?做你自己的LOG文件吧! 你仅需做的事情是用PHP计算实际的点击次数,没有错误,没有象'304 Not Modified' 和 'Internal Server Error' 一样的错误。你的代码将生成自己的LOG文件。 ?php /* 用户定义变量 */ $logfile = "clf.log"; /*LOG文件写到那里 */ $timezone ...
标签: Web开发
代码如下: ?php  class html  {      var $dir;        //dir for the htmls(without/)      var $rootdir;    //root of html files(without/):html  &n...
标签: PHP
  <?php /*  Function Written by Nelson Neoh @3/2004.  For those who wants to utilize this code, please do not remove this remark.  If you have done any enhancement to this code, please post the copy at http://www.dev-club.com PHP board.  Thank you. Function usage: calendar(Month,Year) ...
标签: excel
excel如何生成圆饼形图例?   在excel中,有时表格不能够那么一目了然地了解数据之间的关系,我们喜欢用更直观的图例来向用户展示,其中圆饼形的图是其中的一种,那么如何来生成这种图呢? 1、首先在表格中添加一项总和的数据,如本例中我们加一项SUM 本例中SUM的公式是:=SUM(B2:B5) 然后点插入图表,选择饼图的形...
标签: 办公软件
   在老师的日常工作中,对学生的成绩进行统计分析管理是一项非常重要也是十分麻烦的工作,如果能够利用EXCEL强大的数据处理功能,就可以让各位老师迅速完成对学生的成绩的各项分析统计工作。下面就向各位朋友介绍一些利用EXCEL进行学生成绩管理的小技巧。 一、快速转换学生考试成绩等级 有的时候,会遇到要将学生的考试...

经验教程

21

收藏

66
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部