查看完整版本: php生成EXCEL的东东

Kenny 2007-8-1 22:14

php生成EXCEL的东东

             <p><span class="t18">可以通过<a href="http://www.phpchina.com/javascript:;" onClick="javascript:tagshow(event, 'PHP');" target="_self"><u><strong>PHP</strong></u></a>来产生EXCEL档.&nbsp;&nbsp;teaman翻译 <br>---------------------------- <br>Excel Functions <br>---------------------------- <br>将下面的<a href="http://www.phpchina.com/javascript:;" onClick="javascript:tagshow(event, '%B4%FA%C2%EB');" target="_self"><u><strong>代码</strong></u></a>存为excel.php ,然后在页面中包括进来 <br><br>然后调用 <br>1. Call xlsBOF()&nbsp;&nbsp;<br>2. 将一些内容写入到xlswritenunber() 或者 xlswritelabel()中. <br>3.然后调用 Call xlsEOF() <br><br>也可以用 fwrite 函数直接写到服务器上,而不是用echo 仅仅在浏览器上显示。 <br>&nbsp;&nbsp;&nbsp;<br><br><br>&lt;?php <br>// ----- begin of function library ----- <br>// Excel begin of file header <br>function xlsBOF() { <br>&nbsp;&nbsp;&nbsp;&nbsp;echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;return; <br>} <br>// Excel end of file footer <br>function xlsEOF() { <br>&nbsp;&nbsp;&nbsp;&nbsp;echo pack("ss", 0x0A, 0x00); <br>&nbsp;&nbsp;&nbsp;&nbsp;return; <br>} <br>// Function to write a Number (double) into Row, Col <br>function xlsWriteNumber($Row, $Col, $Value) { <br>&nbsp;&nbsp;&nbsp;&nbsp;echo pack("sssss", 0x203, 14, $Row, $Col, 0x0); <br>&nbsp;&nbsp;&nbsp;&nbsp;echo pack("d", $Value); <br>&nbsp;&nbsp;&nbsp;&nbsp;return; <br>} <br>// Function to write a label (text) into Row, Col <br>function xlsWriteLabel($Row, $Col, $Value ) { <br>&nbsp;&nbsp;&nbsp;&nbsp;$L = strlen($Value); <br>&nbsp;&nbsp;&nbsp;&nbsp;echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L); <br>&nbsp;&nbsp;&nbsp;&nbsp;echo $Value; <br>return; <br>} <br>// ----- end of function library ----- <br>?&gt; <br><br>//&nbsp;&nbsp;<br>// To display the contents directly in a MIME compatible browser&nbsp;&nbsp;<br>// add the following lines on TOP of your PHP file: <br><br>&lt;?php <br>header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); <br>header ("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT"); <br>header ("Cache-Control: no-cache, must-revalidate");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>header ("Pragma: no-cache");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>header ('Content-type: application/x-msexcel'); <br>header ("Content-Disposition: attachment; filename=EmplList.xls" );&nbsp;&nbsp;<br>header ("Content-Description: PHP/INTERBASE Generated Data" ); <br>// <br>// the next lines demonstrate the generation of the Excel stream <br>// <br>xlsBOF();&nbsp;&nbsp;&nbsp;// begin Excel stream <br>xlsWriteLabel(0,0,"This is a label");&nbsp;&nbsp;// write a label in A1, use for dates too <br>xlsWriteNumber(0,1,9999);&nbsp;&nbsp;// write a number B1 <br>xlsEOF(); // close the stream <br>?&gt; <br></span><div>
页: [1]
查看完整版本: php生成EXCEL的东东
PageRank