Merge pull request #5 from stevleibelt/master

updated code base to work with php 5 and above
This commit is contained in:
Carsten Schmitz 2016-01-08 08:40:56 +01:00
commit 8b1d66e09a
9 changed files with 1050 additions and 981 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
# ide related
.idea
# composer related
composer.lock
composer.phar

View File

@ -31,8 +31,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
require_once 'PEAR.php';
require_once 'Spreadsheet/Excel/Writer/Workbook.php';
require_once __DIR__ . '/Writer/Workbook.php';
/**
* Class for writing Excel Spreadsheets. This class should change COMPLETELY.
@ -47,13 +46,12 @@ class Spreadsheet_Excel_Writer extends Spreadsheet_Excel_Writer_Workbook
/**
* The constructor. It just creates a Workbook
*
* @param string $filename The optional filename for the Workbook.
* @return Spreadsheet_Excel_Writer_Workbook The Workbook created
* @param string $fileName The optional filename for the Workbook.
*/
function Spreadsheet_Excel_Writer($filename = '')
public function __construct($fileName = '')
{
$this->_filename = $filename;
$this->Spreadsheet_Excel_Writer_Workbook($filename);
$this->fileName = $fileName;
parent::__construct($fileName);
}
/**
@ -62,13 +60,13 @@ class Spreadsheet_Excel_Writer extends Spreadsheet_Excel_Writer_Workbook
* @param string $filename The filename to use for HTTP headers
* @access public
*/
function send($filename)
public function send($filename)
{
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
header("Pragma: public");
header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="' . $filename .'"');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0,pre-check=0');
header('Pragma: public');
}
/**
@ -78,17 +76,17 @@ class Spreadsheet_Excel_Writer extends Spreadsheet_Excel_Writer_Workbook
* @access public
* @static
* @param integer $row Row for the cell to convert (0-indexed).
* @param integer $col Column for the cell to convert (0-indexed).
* @param integer $column Column for the cell to convert (0-indexed).
* @return string The cell identifier in A1 format
*/
function rowcolToCell($row, $col)
public function rowcolToCell($row, $column)
{
if ($col > 255) { //maximum column value exceeded
return new PEAR_Error("Maximum column value exceeded: $col");
if ($column > 255) { //maximum column value exceeded
return new PEAR_Error('Maximum column value exceeded: ' . $column);
}
$int = (int)($col / 26);
$frac = $col % 26;
$int = (int)($column / 26);
$frac = $column % 26;
$chr1 = '';
if ($int > 0) {
@ -96,9 +94,8 @@ class Spreadsheet_Excel_Writer extends Spreadsheet_Excel_Writer_Workbook
}
$chr2 = chr(ord('A') + $frac);
$row++;
++$row;
return $chr1 . $chr2 . $row;
}
}
?>

View File

@ -32,8 +32,6 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
require_once 'PEAR.php';
/**
* Class for writing Excel BIFF records.
*
@ -57,59 +55,59 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
* The BIFF/Excel version (5).
* @var integer
*/
var $_BIFF_version = 0x0500;
protected $BIFF_version = 0x0500;
/**
* The byte order of this architecture. 0 => little endian, 1 => big endian
* @var integer
*/
var $_byte_order;
protected $byteOrder;
/**
* The string containing the data of the BIFF stream
* @var string
*/
var $_data;
protected $data;
/**
* The size of the data in bytes. Should be the same as strlen($this->_data)
* The size of the data in bytes. Should be the same as strlen($this->data)
* @var integer
*/
var $_datasize;
protected $dataSize;
/**
* The maximun length for a BIFF record. See _addContinue()
* The maximun length for a BIFF record. See addContinue()
* @var integer
* @see _addContinue()
* @see addContinue()
*/
var $_limit;
protected $limit;
/**
* The temporary dir for storing the OLE file
* @var string
*/
var $_tmp_dir;
protected $temporaryDirectory;
/**
* The temporary file for storing the OLE file
* @var string
*/
var $_tmp_file;
protected $temporaryFile;
/**
* Constructor
*
* @access public
*/
function Spreadsheet_Excel_Writer_BIFFwriter()
public function __construct()
{
$this->_byte_order = '';
$this->_data = '';
$this->_datasize = 0;
$this->_limit = 2080;
$this->_tmp_dir = '';
$this->byteOrder = '';
$this->data = '';
$this->dataSize = 0;
$this->limit = 2080;
$this->temporaryDirectory = '';
// Set the byte order
$this->_setByteOrder();
$this->setByteOrder();
}
/**
@ -118,21 +116,23 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
*
* @access private
*/
function _setByteOrder()
protected function setByteOrder()
{
// Check if "pack" gives the required IEEE 64bit float
$teststr = pack("d", 1.2345);
$number = pack("C8", 0x8D, 0x97, 0x6E, 0x12, 0x83, 0xC0, 0xF3, 0x3F);
if ($number == $teststr) {
$testString = pack('d', 1.2345);
$number = pack('C8', 0x8D, 0x97, 0x6E, 0x12, 0x83, 0xC0, 0xF3, 0x3F);
if ($number == $testString) {
$byte_order = 0; // Little Endian
} elseif ($number == strrev($teststr)){
} elseif ($number == strrev($testString)){
$byte_order = 1; // Big Endian
} else {
// Give up. I'll fix this in a later version.
return $this->raiseError("Required floating point format ".
"not supported on this platform.");
return $this->raiseError('Required floating point format ' .
'not supported on this platform.');
}
$this->_byte_order = $byte_order;
$this->byteOrder = $byte_order;
}
/**
@ -141,13 +141,14 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
* @param string $data binary data to prepend
* @access private
*/
function _prepend($data)
protected function prepend($data)
{
if (strlen($data) > $this->_limit) {
$data = $this->_addContinue($data);
if (strlen($data) > $this->limit) {
$data = $this->addContinue($data);
}
$this->_data = $data.$this->_data;
$this->_datasize += strlen($data);
$this->data = $data . $this->data;
$this->dataSize += strlen($data);
}
/**
@ -156,13 +157,14 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
* @param string $data binary data to append
* @access private
*/
function _append($data)
protected function append($data)
{
if (strlen($data) > $this->_limit) {
$data = $this->_addContinue($data);
if (strlen($data) > $this->limit) {
$data = $this->addContinue($data);
}
$this->_data = $this->_data.$data;
$this->_datasize += strlen($data);
$this->data = $this->data . $data;
$this->dataSize += strlen($data);
}
/**
@ -173,28 +175,28 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
* 0x0010 Worksheet.
* @access private
*/
function _storeBof($type)
protected function storeBof($type)
{
$record = 0x0809; // Record identifier
// According to the SDK $build and $year should be set to zero.
// However, this throws a warning in Excel 5. So, use magic numbers.
if ($this->_BIFF_version == 0x0500) {
if ($this->BIFF_version == 0x0500) {
$length = 0x0008;
$unknown = '';
$build = 0x096C;
$year = 0x07C9;
} elseif ($this->_BIFF_version == 0x0600) {
} elseif ($this->BIFF_version == 0x0600) {
$length = 0x0010;
$unknown = pack("VV", 0x00000041, 0x00000006); //unknown last 8 bytes for BIFF8
$build = 0x0DBB;
$year = 0x07CC;
}
$version = $this->_BIFF_version;
$version = $this->BIFF_version;
$header = pack("vv", $record, $length);
$data = pack("vvvv", $version, $type, $build, $year);
$this->_prepend($header . $data . $unknown);
$header = pack('vv', $record, $length);
$data = pack('vvvv', $version, $type, $build, $year);
$this->prepend($header . $data . $unknown);
}
/**
@ -202,12 +204,12 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
*
* @access private
*/
function _storeEof()
protected function storeEof()
{
$record = 0x000A; // Record identifier
$length = 0x0000; // Number of bytes to follow
$header = pack("vv", $record, $length);
$this->_append($header);
$header = pack('vv', $record, $length);
$this->append($header);
}
/**
@ -222,16 +224,16 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
* @return string A very convenient string of continue blocks
* @access private
*/
function _addContinue($data)
protected function addContinue($data)
{
$limit = $this->_limit;
$limit = $this->limit;
$record = 0x003C; // Record identifier
// The first 2080/8224 bytes remain intact. However, we have to change
// the length field of the record.
$tmp = substr($data, 0, 2).pack("v", $limit-4).substr($data, 4, $limit - 4);
$tmp = substr($data, 0, 2).pack('v', $limit-4) . substr($data, 4, $limit - 4);
$header = pack("vv", $record, $limit); // Headers for continue records
$header = pack('vv', $record, $limit); // Headers for continue records
// Retrieve chunks of 2080/8224 bytes +4 for the header.
$data_length = strlen($data);
@ -241,7 +243,7 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
}
// Retrieve the last chunk of data
$header = pack("vv", $record, strlen($data) - $i);
$header = pack('vv', $record, strlen($data) - $i);
$tmp .= $header;
$tmp .= substr($data, $i, strlen($data) - $i);
@ -255,13 +257,13 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
* @param string $dir The dir to be used as temp dir
* @return true if given dir is valid, false otherwise
*/
function setTempDir($dir)
protected function setTempDir($dir)
{
if (is_dir($dir)) {
$this->_tmp_dir = $dir;
$this->temporaryDirectory = $dir;
return true;
}
return false;
}
}
?>

View File

@ -32,8 +32,6 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
require_once 'PEAR.php';
/**
* Class for generating Excel XF records (formats)
*
@ -48,199 +46,199 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
* The index given by the workbook when creating a new format.
* @var integer
*/
var $_xf_index;
protected $_xf_index;
/**
* Index to the FONT record.
* @var integer
*/
var $font_index;
public $font_index;
/**
* The font name (ASCII).
* @var string
*/
var $_font_name;
protected $_font_name;
/**
* Height of font (1/20 of a point)
* @var integer
*/
var $_size;
protected $_size;
/**
* Bold style
* @var integer
*/
var $_bold;
protected $_bold;
/**
* Bit specifiying if the font is italic.
* @var integer
*/
var $_italic;
protected $_italic;
/**
* Index to the cell's color
* @var integer
*/
var $_color;
protected $_color;
/**
* The text underline property
* @var integer
*/
var $_underline;
protected $_underline;
/**
* Bit specifiying if the font has strikeout.
* @var integer
*/
var $_font_strikeout;
protected $_font_strikeout;
/**
* Bit specifiying if the font has outline.
* @var integer
*/
var $_font_outline;
protected $_font_outline;
/**
* Bit specifiying if the font has shadow.
* @var integer
*/
var $_font_shadow;
protected $_font_shadow;
/**
* 2 bytes specifiying the script type for the font.
* @var integer
*/
var $_font_script;
protected $_font_script;
/**
* Byte specifiying the font family.
* @var integer
*/
var $_font_family;
protected $_font_family;
/**
* Byte specifiying the font charset.
* @var integer
*/
var $_font_charset;
protected $_font_charset;
/**
* An index (2 bytes) to a FORMAT record (number format).
* @var integer
*/
var $_num_format;
protected $_num_format;
/**
* Bit specifying if formulas are hidden.
* @var integer
*/
var $_hidden;
protected $_hidden;
/**
* Bit specifying if the cell is locked.
* @var integer
*/
var $_locked;
protected $_locked;
/**
* The three bits specifying the text horizontal alignment.
* @var integer
*/
var $_text_h_align;
protected $_text_h_align;
/**
* Bit specifying if the text is wrapped at the right border.
* @var integer
*/
var $_text_wrap;
protected $_text_wrap;
/**
* The three bits specifying the text vertical alignment.
* @var integer
*/
var $_text_v_align;
protected $_text_v_align;
/**
* 1 bit, apparently not used.
* @var integer
*/
var $_text_justlast;
protected $_text_justlast;
/**
* The two bits specifying the text rotation.
* @var integer
*/
var $_rotation;
protected $_rotation;
/**
* The cell's foreground color.
* @var integer
*/
var $_fg_color;
protected $_fg_color;
/**
* The cell's background color.
* @var integer
*/
var $_bg_color;
protected $_bg_color;
/**
* The cell's background fill pattern.
* @var integer
*/
var $_pattern;
protected $_pattern;
/**
* Style of the bottom border of the cell
* @var integer
*/
var $_bottom;
protected $_bottom;
/**
* Color of the bottom border of the cell.
* @var integer
*/
var $_bottom_color;
protected $_bottom_color;
/**
* Style of the top border of the cell
* @var integer
*/
var $_top;
protected $_top;
/**
* Color of the top border of the cell.
* @var integer
*/
var $_top_color;
protected $_top_color;
/**
* Style of the left border of the cell
* @var integer
*/
var $_left;
protected $_left;
/**
* Color of the left border of the cell.
* @var integer
*/
var $_left_color;
protected $_left_color;
/**
* Style of the right border of the cell
* @var integer
*/
var $_right;
protected $_right;
/**
* Color of the right border of the cell.
* @var integer
*/
var $_right_color;
protected $_right_color;
/**
* Constructor
@ -249,7 +247,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
* @param integer $index the XF index for the format.
* @param array $properties array with properties to be set on initialization.
*/
function Spreadsheet_Excel_Writer_Format($BIFF_version, $index = 0, $properties = array())
public function __construct($BIFF_version, $index = 0, $properties = array())
{
$this->_xf_index = $index;
$this->_BIFF_version = $BIFF_version;
@ -312,7 +310,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
* @param string $style The type of the XF record ('style' or 'cell').
* @return string The XF record
*/
function getXf($style)
public function getXf($style)
{
// Set the type of the XF record and some of the attributes.
if ($style == 'style') {
@ -444,7 +442,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
*
* @return string The FONT record
*/
function getFont()
public function getFont()
{
$dyHeight = $this->_size * 20; // Height of font (1/20 of a point)
$icv = $this->_color; // Index to color palette
@ -492,7 +490,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
/**
* Returns a unique hash key for a font.
* Used by Spreadsheet_Excel_Writer_Workbook::_storeAllFonts()
* Used by Spreadsheet_Excel_Writer_Workbook::storeAllFonts()
*
* The elements that form the key are arranged to increase the probability of
* generating a unique key. Elements that hold a large range of numbers
@ -500,7 +498,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
*
* @return string A key for this font
*/
function getFontKey()
public function getFontKey()
{
$key = "$this->_font_name$this->_size";
$key .= "$this->_font_script$this->_underline";
@ -516,7 +514,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
*
* @return integer The index for the XF record
*/
function getXfIndex()
public function getXfIndex()
{
return($this->_xf_index);
}
@ -530,7 +528,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
* @param string $name_color name of the color (i.e.: 'blue', 'red', etc..). Optional.
* @return integer The color index
*/
function _getColor($name_color = '')
protected function _getColor($name_color = '')
{
$colors = array(
'aqua' => 0x07,
@ -583,7 +581,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
* @access public
* @param string $location alignment for the cell ('left', 'right', etc...).
*/
function setAlign($location)
public function setAlign($location)
{
if (preg_match("/\d/",$location)) {
return; // Ignore numbers
@ -641,7 +639,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
* @access public
* @param string $location alignment for the cell ('left', 'right', etc...).
*/
function setHAlign($location)
public function setHAlign($location)
{
if (preg_match("/\d/",$location)) {
return; // Ignore numbers
@ -681,7 +679,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
* @access public
* @param string $location alignment for the cell ('top', 'vleft', 'vright', etc...).
*/
function setVAlign($location)
public function setVAlign($location)
{
if (preg_match("/\d/",$location)) {
return; // Ignore numbers
@ -714,7 +712,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
*
* @access public
*/
function setMerge()
public function setMerge()
{
$this->setAlign('merge');
}
@ -729,7 +727,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
1 maps to 700 (bold text). Valid range is: 100-1000.
It's Optional, default is 1 (bold).
*/
function setBold($weight = 1)
public function setBold($weight = 1)
{
if ($weight == 1) {
$weight = 0x2BC; // Bold text
@ -757,7 +755,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
* @access public
* @param integer $style style of the cell border. 1 => thin, 2 => thick.
*/
function setBottom($style)
public function setBottom($style)
{
$this->_bottom = $style;
}
@ -768,7 +766,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
* @access public
* @param integer $style style of the cell top border. 1 => thin, 2 => thick.
*/
function setTop($style)
public function setTop($style)
{
$this->_top = $style;
}
@ -779,7 +777,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
* @access public
* @param integer $style style of the cell left border. 1 => thin, 2 => thick.
*/
function setLeft($style)
public function setLeft($style)
{
$this->_left = $style;
}
@ -790,7 +788,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
* @access public
* @param integer $style style of the cell right border. 1 => thin, 2 => thick.
*/
function setRight($style)
public function setRight($style)
{
$this->_right = $style;
}
@ -802,7 +800,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
* @access public
* @param integer $style style to apply for all cell borders. 1 => thin, 2 => thick.
*/
function setBorder($style)
public function setBorder($style)
{
$this->setBottom($style);
$this->setTop($style);
@ -822,7 +820,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
* @param mixed $color The color we are setting. Either a string (like 'blue'),
* or an integer (range is [8...63]).
*/
function setBorderColor($color)
public function setBorderColor($color)
{
$this->setBottomColor($color);
$this->setTopColor($color);
@ -836,7 +834,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
* @access public
* @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
*/
function setBottomColor($color)
public function setBottomColor($color)
{
$value = $this->_getColor($color);
$this->_bottom_color = $value;
@ -848,7 +846,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
* @access public
* @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
*/
function setTopColor($color)
public function setTopColor($color)
{
$value = $this->_getColor($color);
$this->_top_color = $value;
@ -860,7 +858,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
* @access public
* @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
*/
function setLeftColor($color)
public function setLeftColor($color)
{
$value = $this->_getColor($color);
$this->_left_color = $value;
@ -872,7 +870,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
* @access public
* @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
*/
function setRightColor($color)
public function setRightColor($color)
{
$value = $this->_getColor($color);
$this->_right_color = $value;
@ -885,7 +883,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
* @access public
* @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
*/
function setFgColor($color)
public function setFgColor($color)
{
$value = $this->_getColor($color);
$this->_fg_color = $value;
@ -900,7 +898,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
* @access public
* @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
*/
function setBgColor($color)
public function setBgColor($color)
{
$value = $this->_getColor($color);
$this->_bg_color = $value;
@ -915,7 +913,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
* @access public
* @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
*/
function setColor($color)
public function setColor($color)
{
$value = $this->_getColor($color);
$this->_color = $value;
@ -928,7 +926,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
* @param integer $arg Optional. Defaults to 1. Meaningful values are: 0-18,
* 0 meaning no background.
*/
function setPattern($arg = 1)
public function setPattern($arg = 1)
{
$this->_pattern = $arg;
}
@ -940,7 +938,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
* @param integer $underline The value for underline. Possible values are:
* 1 => underline, 2 => double underline.
*/
function setUnderline($underline)
public function setUnderline($underline)
{
$this->_underline = $underline;
}
@ -950,7 +948,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
*
* @access public
*/
function setItalic()
public function setItalic()
{
$this->_italic = 1;
}
@ -961,7 +959,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
* @access public
* @param integer $size The font size (in pixels I think).
*/
function setSize($size)
public function setSize($size)
{
$this->_size = $size;
}
@ -971,7 +969,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
*
* @access public
*/
function setTextWrap()
public function setTextWrap()
{
$this->_text_wrap = 1;
}
@ -983,7 +981,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
* @param integer $angle The rotation angle for the text (clockwise). Possible
values are: 0, 90, 270 and -1 for stacking top-to-bottom.
*/
function setTextRotation($angle)
public function setTextRotation($angle)
{
switch ($angle)
{
@ -1027,7 +1025,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
* @access public
* @param integer $num_format The numeric format.
*/
function setNumFormat($num_format)
public function setNumFormat($num_format)
{
$this->_num_format = $num_format;
}
@ -1037,7 +1035,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
*
* @access public
*/
function setStrikeOut()
public function setStrikeOut()
{
$this->_font_strikeout = 1;
}
@ -1047,7 +1045,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
*
* @access public
*/
function setOutLine()
public function setOutLine()
{
$this->_font_outline = 1;
}
@ -1057,7 +1055,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
*
* @access public
*/
function setShadow()
public function setShadow()
{
$this->_font_shadow = 1;
}
@ -1069,7 +1067,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
* @param integer $script The value for script type. Possible values are:
* 1 => superscript, 2 => subscript.
*/
function setScript($script)
public function setScript($script)
{
$this->_font_script = $script;
}
@ -1079,7 +1077,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
*
* @access public
*/
function setLocked()
public function setLocked()
{
$this->_locked = 1;
}
@ -1089,7 +1087,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
*
* @access public
*/
function setUnLocked()
public function setUnLocked()
{
$this->_locked = 0;
}
@ -1101,7 +1099,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
* @param string $fontfamily The font family name. Possible values are:
* 'Times New Roman', 'Arial', 'Courier'.
*/
function setFontFamily($font_family)
public function setFontFamily($font_family)
{
$this->_font_name = $font_family;
}

View File

@ -25,79 +25,77 @@
/**
* @const SPREADSHEET_EXCEL_WRITER_ADD token identifier for character "+"
*/
define('SPREADSHEET_EXCEL_WRITER_ADD', "+");
define('SPREADSHEET_EXCEL_WRITER_ADD', '+');
/**
* @const SPREADSHEET_EXCEL_WRITER_SUB token identifier for character "-"
*/
define('SPREADSHEET_EXCEL_WRITER_SUB', "-");
define('SPREADSHEET_EXCEL_WRITER_SUB', '-');
/**
* @const SPREADSHEET_EXCEL_WRITER_MUL token identifier for character "*"
*/
define('SPREADSHEET_EXCEL_WRITER_MUL', "*");
define('SPREADSHEET_EXCEL_WRITER_MUL', '*');
/**
* @const SPREADSHEET_EXCEL_WRITER_DIV token identifier for character "/"
*/
define('SPREADSHEET_EXCEL_WRITER_DIV', "/");
define('SPREADSHEET_EXCEL_WRITER_DIV', '/');
/**
* @const SPREADSHEET_EXCEL_WRITER_OPEN token identifier for character "("
*/
define('SPREADSHEET_EXCEL_WRITER_OPEN', "(");
define('SPREADSHEET_EXCEL_WRITER_OPEN', '(');
/**
* @const SPREADSHEET_EXCEL_WRITER_CLOSE token identifier for character ")"
*/
define('SPREADSHEET_EXCEL_WRITER_CLOSE', ")");
define('SPREADSHEET_EXCEL_WRITER_CLOSE', ')');
/**
* @const SPREADSHEET_EXCEL_WRITER_COMA token identifier for character ","
*/
define('SPREADSHEET_EXCEL_WRITER_COMA', ",");
define('SPREADSHEET_EXCEL_WRITER_COMA', ',');
/**
* @const SPREADSHEET_EXCEL_WRITER_SEMICOLON token identifier for character ";"
*/
define('SPREADSHEET_EXCEL_WRITER_SEMICOLON', ";");
define('SPREADSHEET_EXCEL_WRITER_SEMICOLON', ';');
/**
* @const SPREADSHEET_EXCEL_WRITER_GT token identifier for character ">"
*/
define('SPREADSHEET_EXCEL_WRITER_GT', ">");
define('SPREADSHEET_EXCEL_WRITER_GT', '>');
/**
* @const SPREADSHEET_EXCEL_WRITER_LT token identifier for character "<"
*/
define('SPREADSHEET_EXCEL_WRITER_LT', "<");
define('SPREADSHEET_EXCEL_WRITER_LT', '<');
/**
* @const SPREADSHEET_EXCEL_WRITER_LE token identifier for character "<="
*/
define('SPREADSHEET_EXCEL_WRITER_LE', "<=");
define('SPREADSHEET_EXCEL_WRITER_LE', '<=');
/**
* @const SPREADSHEET_EXCEL_WRITER_GE token identifier for character ">="
*/
define('SPREADSHEET_EXCEL_WRITER_GE', ">=");
define('SPREADSHEET_EXCEL_WRITER_GE', '>=');
/**
* @const SPREADSHEET_EXCEL_WRITER_EQ token identifier for character "="
*/
define('SPREADSHEET_EXCEL_WRITER_EQ', "=");
define('SPREADSHEET_EXCEL_WRITER_EQ', '=');
/**
* @const SPREADSHEET_EXCEL_WRITER_NE token identifier for character "<>"
*/
define('SPREADSHEET_EXCEL_WRITER_NE', "<>");
define('SPREADSHEET_EXCEL_WRITER_NE', '<>');
/**
* * @const SPREADSHEET_EXCEL_WRITER_CONCAT token identifier for character "&"
*/
define('SPREADSHEET_EXCEL_WRITER_CONCAT', "&");
require_once 'PEAR.php';
define('SPREADSHEET_EXCEL_WRITER_CONCAT', '&');
/**
* Class for parsing Excel formulas
@ -113,55 +111,55 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
* The index of the character we are currently looking at
* @var integer
*/
var $_current_char;
protected $_current_char;
/**
* The token we are working on.
* @var string
*/
var $_current_token;
protected $_current_token;
/**
* The formula to parse
* @var string
*/
var $_formula;
protected $_formula;
/**
* The character ahead of the current char
* @var string
*/
var $_lookahead;
protected $_lookahead;
/**
* The parse tree to be generated
* @var string
*/
var $_parse_tree;
protected $_parse_tree;
/**
* The byte order. 1 => big endian, 0 => little endian.
* @var integer
*/
var $_byte_order;
protected $_byte_order;
/**
* Array of external sheets
* @var array
*/
var $_ext_sheets;
protected $_ext_sheets;
/**
* Array of sheet references in the form of REF structures
* @var array
*/
var $_references;
protected $_references;
/**
* The BIFF version for the workbook
* @var integer
*/
var $_BIFF_version;
protected $_BIFF_version;
/**
* The class constructor
@ -169,7 +167,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
* @param integer $byte_order The byte order (Little endian or Big endian) of the architecture
(optional). 1 => big endian, 0 (default) little endian.
*/
function Spreadsheet_Excel_Writer_Parser($byte_order, $biff_version)
public function __construct($byte_order, $biff_version)
{
$this->_current_char = 0;
$this->_BIFF_version = $biff_version;
@ -188,7 +186,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
*
* @access private
*/
function _initializeHashes()
protected function _initializeHashes()
{
// The Excel ptg indices
$this->ptg = array(
@ -540,7 +538,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
* @return mixed the converted token on success. PEAR_Error if the token
* is not recognized
*/
function _convert($token)
protected function _convert($token)
{
if (preg_match("/^\"[^\"]{0,255}\"$/", $token)) {
return $this->_convertString($token);
@ -600,7 +598,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
* @access private
* @param mixed $num an integer or double for conversion to its ptg value
*/
function _convertNumber($num)
protected function _convertNumber($num)
{
// Integer in the range 0..2**16-1
if ((preg_match("/^\d+$/", $num)) and ($num <= 65535)) {
@ -621,7 +619,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
* @return mixed the converted token on success. PEAR_Error if the string
* is longer than 255 characters.
*/
function _convertString($string)
protected function _convertString($string)
{
// chop away beggining and ending quotes
$string = substr($string, 1, strlen($string) - 2);
@ -646,7 +644,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
* @param integer $num_args The number of arguments the function receives.
* @return string The packed ptg for the function
*/
function _convertFunction($token, $num_args)
protected function _convertFunction($token, $num_args)
{
$args = $this->_functions[$token][1];
$volatile = $this->_functions[$token][3];
@ -667,7 +665,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
* @access private
* @param string $range An Excel range in the A1:A2 or A1..A2 format.
*/
function _convertRange2d($range, $class=0)
protected function _convertRange2d($range, $class=0)
{
// TODO: possible class value 0,1,2 check Formula.pm
@ -716,7 +714,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
* @param string $token An Excel range in the Sheet1!A1:A2 format.
* @return mixed The packed ptgArea3d token on success, PEAR_Error on failure.
*/
function _convertRange3d($token)
protected function _convertRange3d($token)
{
$class = 2; // as far as I know, this is magick.
@ -780,7 +778,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
* @param string $cell An Excel cell reference
* @return string The cell in packed() format with the corresponding ptg
*/
function _convertRef2d($cell)
protected function _convertRef2d($cell)
{
$class = 2; // as far as I know, this is magick.
@ -813,7 +811,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
* @param string $cell An Excel cell reference
* @return mixed The packed ptgRef3d token on success, PEAR_Error on failure.
*/
function _convertRef3d($cell)
protected function _convertRef3d($cell)
{
$class = 2; // as far as I know, this is magick.
@ -858,7 +856,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
* @param string $ext_ref The name of the external reference
* @return string The reference index in packed() format
*/
function _packExtRef($ext_ref)
protected function _packExtRef($ext_ref)
{
$ext_ref = preg_replace("/^'/", '', $ext_ref); // Remove leading ' if any.
$ext_ref = preg_replace("/'$/", '', $ext_ref); // Remove trailing ' if any.
@ -904,7 +902,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
* @return mixed The reference index in packed() format on success,
* PEAR_Error on failure
*/
function _getRefIndex($ext_ref)
protected function _getRefIndex($ext_ref)
{
$ext_ref = preg_replace("/^'/", '', $ext_ref); // Remove leading ' if any.
$ext_ref = preg_replace("/'$/", '', $ext_ref); // Remove trailing ' if any.
@ -962,7 +960,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
* @access private
* @return integer The sheet index, -1 if the sheet was not found
*/
function _getSheetIndex($sheet_name)
protected function _getSheetIndex($sheet_name)
{
if (!isset($this->_ext_sheets[$sheet_name])) {
return -1;
@ -981,7 +979,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
* @param string $name The name of the worksheet being added
* @param integer $index The index of the worksheet being added
*/
function setExtSheet($name, $index)
public function setExtSheet($name, $index)
{
$this->_ext_sheets[$name] = $index;
}
@ -993,7 +991,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
* @param string $cell The Excel cell reference to be packed
* @return array Array containing the row and column in packed() format
*/
function _cellToPackedRowcol($cell)
protected function _cellToPackedRowcol($cell)
{
$cell = strtoupper($cell);
list($row, $col, $row_rel, $col_rel) = $this->_cellToRowcol($cell);
@ -1028,7 +1026,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
* @param string $range The Excel range to be packed
* @return array Array containing (row1,col1,row2,col2) in packed() format
*/
function _rangeToPackedRange($range)
protected function _rangeToPackedRange($range)
{
preg_match('/(\$)?(\d+)\:(\$)?(\d+)/', $range, $match);
// return absolute rows if there is a $ in the ref
@ -1075,7 +1073,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
* @param string $cell The Excel cell reference in A1 format.
* @return array
*/
function _cellToRowcol($cell)
protected function _cellToRowcol($cell)
{
preg_match('/(\$)?([A-I]?[A-Z])(\$)?(\d+)/',$cell,$match);
// return absolute column if there is a $ in the ref
@ -1105,7 +1103,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
*
* @access private
*/
function _advance()
protected function _advance()
{
$i = $this->_current_char;
$formula_length = strlen($this->_formula);
@ -1155,7 +1153,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
* @param mixed $token The token to check.
* @return mixed The checked token or false on failure
*/
function _match($token)
protected function _match($token)
{
switch($token) {
case SPREADSHEET_EXCEL_WRITER_ADD:
@ -1286,7 +1284,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
* sign (=).
* @return mixed true on success, PEAR_Error on failure
*/
function parse($formula)
public function parse($formula)
{
$this->_current_char = 0;
$this->_formula = $formula;
@ -1306,7 +1304,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
* @access private
* @return mixed The parsed ptg'd tree on success, PEAR_Error on failure
*/
function _condition()
protected function _condition()
{
$result = $this->_expression();
if (PEAR::isError($result)) {
@ -1374,7 +1372,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
* @access private
* @return mixed The parsed ptg'd tree on success, PEAR_Error on failure
*/
function _expression()
protected function _expression()
{
// If it's a string return a string node
if (preg_match("/^\"[^\"]{0,255}\"$/", $this->_current_token)) {
@ -1422,7 +1420,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
* @see _fact()
* @return array The parsed ptg'd tree
*/
function _parenthesizedExpression()
protected function _parenthesizedExpression()
{
$result = $this->_createTree('ptgParen', $this->_expression(), '');
return $result;
@ -1435,7 +1433,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
* @access private
* @return mixed The parsed ptg'd tree on success, PEAR_Error on failure
*/
function _term()
protected function _term()
{
$result = $this->_fact();
if (PEAR::isError($result)) {
@ -1474,7 +1472,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
* @access private
* @return mixed The parsed ptg'd tree on success, PEAR_Error on failure
*/
function _fact()
protected function _fact()
{
if ($this->_current_token == SPREADSHEET_EXCEL_WRITER_OPEN) {
$this->_advance(); // eat the "("
@ -1552,7 +1550,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
* @access private
* @return mixed The parsed ptg'd tree on success, PEAR_Error on failure
*/
function _func()
protected function _func()
{
$num_args = 0; // number of arguments received
$function = strtoupper($this->_current_token);
@ -1608,7 +1606,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
* @param mixed $right The right array (sub-tree) or a final node.
* @return array A tree
*/
function _createTree($value, $left, $right)
protected function _createTree($value, $left, $right)
{
return array('value' => $value, 'left' => $left, 'right' => $right);
}
@ -1640,7 +1638,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
* @param array $tree The optional tree to convert.
* @return string The tree in reverse polish notation
*/
function toReversePolish($tree = array())
public function toReversePolish($tree = array())
{
$polish = ""; // the string we are going to return
if (empty($tree)) { // If it's the first call use _parse_tree

View File

@ -22,21 +22,19 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
//require_once('PEAR.php');
// Possible operator types
/*
FIXME: change prefixes
*/
define("OP_BETWEEN", 0x00);
define("OP_NOTBETWEEN", 0x01);
define("OP_EQUAL", 0x02);
define("OP_NOTEQUAL", 0x03);
define("OP_GT", 0x04);
define("OP_LT", 0x05);
define("OP_GTE", 0x06);
define("OP_LTE", 0x07);
define('OP_BETWEEN', 0x00);
define('OP_NOTBETWEEN', 0x01);
define('OP_EQUAL', 0x02);
define('OP_NOTEQUAL', 0x03);
define('OP_GT', 0x04);
define('OP_LT', 0x05);
define('OP_GTE', 0x06);
define('OP_LTE', 0x07);
/**
* Baseclass for generating Excel DV records (validations)
@ -47,27 +45,27 @@ define("OP_LTE", 0x07);
*/
class Spreadsheet_Excel_Writer_Validator
{
var $_type;
var $_style;
var $_fixedList;
var $_blank;
var $_incell;
var $_showprompt;
var $_showerror;
var $_title_prompt;
var $_descr_prompt;
var $_title_error;
var $_descr_error;
var $_operator;
var $_formula1;
var $_formula2;
protected $_type;
protected $_style;
protected $_fixedList;
protected $_blank;
protected $_incell;
protected $_showprompt;
protected $_showerror;
protected $_title_prompt;
protected $_descr_prompt;
protected $_title_error;
protected $_descr_error;
protected $_operator;
protected $_formula1;
protected $_formula2;
/**
* The parser from the workbook. Used to parse validation formulas also
* @var Spreadsheet_Excel_Writer_Parser
*/
var $_parser;
protected $_parser;
function Spreadsheet_Excel_Writer_Validator(&$parser)
public function __construct($parser)
{
$this->_parser = $parser;
$this->_type = 0x01; // FIXME: add method for setting datatype
@ -86,41 +84,41 @@ class Spreadsheet_Excel_Writer_Validator
$this->_formula2 = '';
}
function setPrompt($promptTitle = "\x00", $promptDescription = "\x00", $showPrompt = true)
public function setPrompt($promptTitle = "\x00", $promptDescription = "\x00", $showPrompt = true)
{
$this->_showprompt = $showPrompt;
$this->_title_prompt = $promptTitle;
$this->_descr_prompt = $promptDescription;
}
function setError($errorTitle = "\x00", $errorDescription = "\x00", $showError = true)
public function setError($errorTitle = "\x00", $errorDescription = "\x00", $showError = true)
{
$this->_showerror = $showError;
$this->_title_error = $errorTitle;
$this->_descr_error = $errorDescription;
}
function allowBlank()
public function allowBlank()
{
$this->_blank = true;
}
function onInvalidStop()
public function onInvalidStop()
{
$this->_style = 0x00;
}
function onInvalidWarn()
public function onInvalidWarn()
{
$this->_style = 0x01;
}
function onInvalidInfo()
public function onInvalidInfo()
{
$this->_style = 0x02;
}
function setFormula1($formula)
public function setFormula1($formula)
{
// Parse the formula using the parser in Parser.php
$error = $this->_parser->parse($formula);
@ -135,7 +133,7 @@ class Spreadsheet_Excel_Writer_Validator
return true;
}
function setFormula2($formula)
public function setFormula2($formula)
{
// Parse the formula using the parser in Parser.php
$error = $this->_parser->parse($formula);
@ -150,7 +148,7 @@ class Spreadsheet_Excel_Writer_Validator
return true;
}
function _getOptions()
public function _getOptions()
{
$options = $this->_type;
$options |= $this->_style << 3;
@ -174,7 +172,7 @@ class Spreadsheet_Excel_Writer_Validator
return $options;
}
function _getData()
public function _getData()
{
$title_prompt_len = strlen($this->_title_prompt);
$descr_prompt_len = strlen($this->_descr_prompt);
@ -199,13 +197,13 @@ class Spreadsheet_Excel_Writer_Validator
/*class Spreadsheet_Excel_Writer_Validation_List extends Spreadsheet_Excel_Writer_Validation
{
function Spreadsheet_Excel_Writer_Validation_list()
public function Spreadsheet_Excel_Writer_Validation_list()
{
parent::Spreadsheet_Excel_Writer_Validation();
$this->_type = 0x03;
}
function setList($source, $incell = true)
public function setList($source, $incell = true)
{
$this->_incell = $incell;
$this->_fixedList = true;
@ -214,13 +212,13 @@ class Spreadsheet_Excel_Writer_Validator
$this->_formula1 = pack("CCC", 0x17, strlen($source), 0x0c) . $source;
}
function setRow($row, $col1, $col2, $incell = true)
public function setRow($row, $col1, $col2, $incell = true)
{
$this->_incell = $incell;
//$this->_formula1 = ...;
}
function setCol($col, $row1, $row2, $incell = true)
public function setCol($col, $row1, $row2, $incell = true)
{
$this->_incell = $incell;
//$this->_formula1 = ...;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -31,6 +31,7 @@
"./"
],
"license": "LGPL",
"minimum-stability": "dev",
"name": "pear/spreadsheet_excel_writer",
"support": {
"issues": "http://pear.php.net/bugs/search.php?cmd=display&package_name[]=Spreadsheet_Excel_Writer",
@ -38,8 +39,9 @@
},
"type": "library",
"require": {
"pear/pear_exception": "*",
"pear/ole": "*"
"pear/pear": "*",
"pear/ole": "*",
"php": ">=5.3.3"
},
"require-dev": {
"phpunit/phpunit": "*"