<?
php
class excel
{
/*
require_once("excel.php");
$title=array("标题一","标题二","标题三");
$data=array(array(1,2,3),array(4,5,6),array(7,8,9));
$myexcel= new excel($title,$data,"myfile.xsl");
$myexcel->createexcel();
*/
var $titles ; // 标题
var $datas ; // 数据数组
var $filename ; // 文件名
var $splits ; // 分隔符
function excel ( $titles = array () , $datas = array () , $filename = " my.xsl " , $split = " " )
{
$this -> titles = $titles ;
$this -> datas = $datas ;
$this -> filename = $filename ;
$this -> splits = $split ;
}
function excelheader()
{
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= " . $this -> filename );
header ( " Content-Description: PHP/INTERBASE Generated Data " );
}
function createexcel()
{
$this -> excelheader();
$title = implode ( $this -> splits , $this -> titles) . " " ;
echo $title ;
for ( $i = 0 ; $i < count ( $this -> datas); $i ++ )
{
if ( ! is_array ( $this -> datas[ $i ]))
{
echo $this -> datas[ $i ] . " " ;
}
else
{
echo implode ( $this -> splits , $this -> datas[ $i ]) . " " ;
}
}
}
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 ;
}
}
?>
class excel
{
/*
require_once("excel.php");
$title=array("标题一","标题二","标题三");
$data=array(array(1,2,3),array(4,5,6),array(7,8,9));
$myexcel= new excel($title,$data,"myfile.xsl");
$myexcel->createexcel();
*/
var $titles ; // 标题
var $datas ; // 数据数组
var $filename ; // 文件名
var $splits ; // 分隔符
function excel ( $titles = array () , $datas = array () , $filename = " my.xsl " , $split = " " )
{
$this -> titles = $titles ;
$this -> datas = $datas ;
$this -> filename = $filename ;
$this -> splits = $split ;
}
function excelheader()
{
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= " . $this -> filename );
header ( " Content-Description: PHP/INTERBASE Generated Data " );
}
function createexcel()
{
$this -> excelheader();
$title = implode ( $this -> splits , $this -> titles) . " " ;
echo $title ;
for ( $i = 0 ; $i < count ( $this -> datas); $i ++ )
{
if ( ! is_array ( $this -> datas[ $i ]))
{
echo $this -> datas[ $i ] . " " ;
}
else
{
echo implode ( $this -> splits , $this -> datas[ $i ]) . " " ;
}
}
}
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 ;
}
}
?>