code cleanup

git-svn-id: https://svn.php.net/repository/pear/packages/Spreadsheet_Excel_Writer/trunk@141423 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Xavier Noguer Gallego 2003-10-01 09:17:45 +00:00
parent 7641474dfb
commit e461d9b467
1 changed files with 60 additions and 62 deletions

View File

@ -1,6 +1,6 @@
<?php <?php
/* /*
* Module written/ported by Xavier Noguer <xnoguer@rezebra.com> * Module written/ported by Xavier Noguer <xnoguer@php.net>
* *
* The majority of this is _NOT_ my code. I simply ported it from the * The majority of this is _NOT_ my code. I simply ported it from the
* PERL Spreadsheet::WriteExcel module. * PERL Spreadsheet::WriteExcel module.
@ -15,7 +15,7 @@
* License Information: * License Information:
* *
* Spreadsheet_Excel_Writer: A library for generating Excel Spreadsheets * Spreadsheet_Excel_Writer: A library for generating Excel Spreadsheets
* Copyright (c) 2002-2003 Xavier Noguer xnoguer@rezebra.com * Copyright (c) 2002-2003 Xavier Noguer xnoguer@php.net
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -46,7 +46,7 @@ require_once('PEAR.php');
* formula entered into a cell; one describes the size and location of a * formula entered into a cell; one describes the size and location of a
* window into a document; another describes a picture format. * window into a document; another describes a picture format.
* *
* @author Xavier Noguer <xnoguer@rezebra.com> * @author Xavier Noguer <xnoguer@php.net>
* @category FileFormats * @category FileFormats
* @package Spreadsheet_Excel_Writer * @package Spreadsheet_Excel_Writer
*/ */
@ -99,40 +99,37 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
$this->_setByteOrder(); $this->_setByteOrder();
} }
/** /**
* Determine the byte order and store it as class data to avoid * Determine the byte order and store it as class data to avoid
* recalculating it for each call to new(). * recalculating it for each call to new().
* *
* @access private * @access private
*/ */
function _setByteOrder() function _setByteOrder()
{ {
if ($this->_byte_order == '') // Check if "pack" gives the required IEEE 64bit float
{ $teststr = pack("d", 1.2345);
// Check if "pack" gives the required IEEE 64bit float $number = pack("C8", 0x8D, 0x97, 0x6E, 0x12, 0x83, 0xC0, 0xF3, 0x3F);
$teststr = pack("d", 1.2345); if ($number == $teststr) {
$number = pack("C8", 0x8D, 0x97, 0x6E, 0x12, 0x83, 0xC0, 0xF3, 0x3F); $byte_order = 0; // Little Endian
if ($number == $teststr) { }
$byte_order = 0; // Little Endian elseif ($number == strrev($teststr)){
} $byte_order = 1; // Big Endian
elseif ($number == strrev($teststr)){ }
$byte_order = 1; // Big Endian else {
} // Give up. I'll fix this in a later version.
else { return $this->raiseError("Required floating point format ".
// Give up. I'll fix this in a later version. "not supported on this platform.");
$this->raiseError("Required floating point format not supported ".
"on this platform.");
}
} }
$this->_byte_order = $byte_order; $this->_byte_order = $byte_order;
} }
/** /**
* General storage function * General storage function
* *
* @param string $data binary data to prepend * @param string $data binary data to prepend
* @access private * @access private
*/ */
function _prepend($data) function _prepend($data)
{ {
if (strlen($data) > $this->_limit) { if (strlen($data) > $this->_limit) {
@ -142,12 +139,12 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
$this->_datasize += strlen($data); $this->_datasize += strlen($data);
} }
/** /**
* General storage function * General storage function
* *
* @param string $data binary data to append * @param string $data binary data to append
* @access private * @access private
*/ */
function _append($data) function _append($data)
{ {
if (strlen($data) > $this->_limit) { if (strlen($data) > $this->_limit) {
@ -157,13 +154,14 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
$this->_datasize += strlen($data); $this->_datasize += strlen($data);
} }
/** /**
* Writes Excel BOF record to indicate the beginning of a stream or * Writes Excel BOF record to indicate the beginning of a stream or
* sub-stream in the BIFF file. * sub-stream in the BIFF file.
* *
* @param integer $type type of BIFF file to write: 0x0005 Workbook, 0x0010 Worksheet. * @param integer $type Type of BIFF file to write: 0x0005 Workbook,
* @access private * 0x0010 Worksheet.
*/ * @access private
*/
function _storeBof($type) function _storeBof($type)
{ {
$record = 0x0809; // Record identifier $record = 0x0809; // Record identifier
@ -181,11 +179,11 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
$this->_prepend($header.$data); $this->_prepend($header.$data);
} }
/** /**
* Writes Excel EOF record to indicate the end of a BIFF stream. * Writes Excel EOF record to indicate the end of a BIFF stream.
* *
* @access private * @access private
*/ */
function _storeEof() function _storeEof()
{ {
$record = 0x000A; // Record identifier $record = 0x000A; // Record identifier
@ -194,18 +192,18 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
$this->_append($header); $this->_append($header);
} }
/** /**
* Excel limits the size of BIFF records. In Excel 5 the limit is 2084 bytes. In * Excel limits the size of BIFF records. In Excel 5 the limit is 2084 bytes. In
* Excel 97 the limit is 8228 bytes. Records that are longer than these limits * Excel 97 the limit is 8228 bytes. Records that are longer than these limits
* must be split up into CONTINUE blocks. * must be split up into CONTINUE blocks.
* *
* This function takes a long BIFF record and inserts CONTINUE records as * This function takes a long BIFF record and inserts CONTINUE records as
* necessary. * necessary.
* *
* @param string $data The original binary data to be written * @param string $data The original binary data to be written
* @return string A very convenient string of continue blocks * @return string A very convenient string of continue blocks
* @access private * @access private
*/ */
function _addContinue($data) function _addContinue($data)
{ {
$limit = $this->_limit; $limit = $this->_limit;
@ -229,7 +227,7 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
$tmp .= $header; $tmp .= $header;
$tmp .= substr($data,$i,strlen($data) - $i); $tmp .= substr($data,$i,strlen($data) - $i);
return($tmp); return $tmp;
} }
} }
?> ?>