[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] property/inc class.excel.inc.php,NONE,1.1
From: |
Sigurd Nes <address@hidden> |
Subject: |
[Phpgroupware-cvs] property/inc class.excel.inc.php,NONE,1.1 |
Date: |
Sun, 05 Oct 2003 16:46:39 +0000 |
Update of /cvsroot/phpgroupware/property/inc
In directory subversions:/tmp/cvs-serv29362/inc
Added Files:
class.excel.inc.php
Log Message:
no message
--- NEW FILE: class.excel.inc.php ---
<?php
// +----------------------------------------------------------------------+
// | PHP Class for generating Excel binary data. (PHP 4 >= 4.0b1) |
// +----------------------------------------------------------------------+
// | Copyright (c) 2001 by KVN |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | address@hidden so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Author: Vitaliy N. Kravchenko <address@hidden> |
// +----------------------------------------------------------------------+
//
// $Id: class.excel.inc.php,v 1.1 2003/10/05 16:46:36 sigurdne Exp $ Thu Jul 11
EEST 2002 version 2.5
/*
Usage Example:
-----------------------------------------------------------
$xls = new Excel(false); // begin Excel stream, start Excel and dont ask
"Save"..
while($row = $res->fetchRow())
{
$line++;
for ($i=0; $i<count($row); $i++)
{
$xls->WriteLabel($line,$i,$row[$i]);
}
}
$xls->SendFile("moe.xls"); // close the stream
Also present Function to write a Number (double) into Row, Col:
$xls->WriteNumber($Row,$Col,$Number);
Example2:
$str = Excel::WriteLabel(1,1,"Hello World!");
$str .= Excel::WriteNumber(1,2,671);
header(..);
echo Excel::Begin();
echo $str;
echo Excel::EOF();
Examle3:
header(....)
$xls = new Excel();
$xls->.... WriteNumber/Label..
echo $xls->GetData();
*/
/**
* @package Excel
* @version 2.5
* @author Vitaliy N. Kravchenko <address@hidden>
* @since PHP 4.0.4
*
*/
class excel extends PEAR {
var $xls_data = "";
var $error = "";
var $download = "true";
/**
* Constructor, writting begin of Excel file (binary).
*
* @param $download boolean true, if ask for "Save/Open", false -
* if open Excel (application/x-exel).
*/
function excel($download = "true") {
$this->download = $download;
$this->Begin();
}
/**
* Excel begin of file header
* Send the header to client
*
* @param $filename string - name of file, for save
* (actually, if $download = true)
*/
function _Header($filename) {
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");
if ($this->download){
header ("Content-type: application/x-msexcel");
header ("Content-Disposition: attachment; filename=$filename" );
} else {
header ("Content-type: application/msexcel");
}
header ("Content-Description: PHP Generated Data" );
}
/**
* Begin of Excel File.
*
* @private
*/
function Begin() {
$str = pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
$this->xls_data = $str;
return $str;
}
/**
* End of Excel File (binary)
*
* @private
*/
function EOF() {
$str = pack("ss", 0x0A, 0x00);
$this->xls_data .= $str;
return $str;
}
/**
* Function for writting number (double) into row $Row,
* and column $Col.
*
* @param $Row integer - Row
* @param $Col integer - Column
* @param $Value number - value
*
*/
function WriteNumber($Row, $Col, $Value) {
$str = pack("sssss", 0x203, 14, $Row, $Col, 0x0);
$str .= pack("d", $Value);
$this->xls_data .= $str;
return $str;
}
/**
* Function for writting label(string) into row $Row,
* and column $Col.
* @param $Row integer - Row
* @param $Col integer - Column
* @param $Value number - value
*
*/
function WriteLabel($Row, $Col, $Value ) {
$L = strlen($Value);
$str = pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
$str .= $Value;
$this->xls_data .= $str;
return $str;
}
/**
* Function to send file to client(browser)
*
* @param $filename string - name of file (actually, if $download = true)
*
*/
function SendFile($filename = "test.xls") {
$this->_Header($filename);
echo $this->xls_data;
echo $this->EOF();
}
/**
* Function to get Excel (binary) data
*
* @param $eof boolean - id true, returnet data will with the end of Excel
File (bin)
*
*/
function GetData($eof = "true") {
if ($eof) return $xls_data . $this->EOF();
else return $xls_data;
}
/**
* Function to write Excel-data to $file
*
* @param $efile string - File name.
*
*/
function toFile($file = "test.xls") {
$fp = @fopen($file,"w");
if (is_resource($fp)) {
fwrite($fp, $this->xls_data);
fclose($fp);
return true;
} else {
return $this->raiseError("Can't access to '$file' for
writting!",-1);
}
}
/**
* Destructor
* Unset The Excel Object.
*
* @private
*
*/
function _Excel()
{
unset($this->xls_data);
unset ($this);
}
} // End of class Excel.
?>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] property/inc class.excel.inc.php,NONE,1.1,
Sigurd Nes <address@hidden> <=
- Prev by Date:
[Phpgroupware-cvs] admin/inc class.uiaccounts.inc.php, 1.23.2.9.2.18, 1.23.2.9.2.19
- Next by Date:
[Phpgroupware-cvs] property/templates/default columns.xsl, NONE, 1.1 date_search.xsl, NONE, 1.1
- Previous by thread:
[Phpgroupware-cvs] admin/inc class.uiaccounts.inc.php, 1.23.2.9.2.18, 1.23.2.9.2.19
- Next by thread:
[Phpgroupware-cvs] property/templates/default columns.xsl, NONE, 1.1 date_search.xsl, NONE, 1.1
- Index(es):