Merge pull request #8 from sanmai/fixtures

Fix errors, add tests with fixtrues
This commit is contained in:
Carsten Schmitz 2016-06-16 07:20:58 +02:00 committed by GitHub
commit c91cd95ffa
18 changed files with 955 additions and 906 deletions

2
.gitignore vendored
View File

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

View File

@ -31,7 +31,9 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
require_once __DIR__ . '/Writer/Workbook.php';
if (!class_exists('Spreadsheet_Excel_Writer_Workbook')) {
require_once 'Spreadsheet/Excel/Writer/Workbook.php';
}
/**
* Class for writing Excel Spreadsheets. This class should change COMPLETELY.
@ -46,12 +48,13 @@ 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.
* @param string $filename The optional filename for the Workbook.
* @return Spreadsheet_Excel_Writer_Workbook The Workbook created
*/
public function __construct($fileName = '')
public function __construct($filename = '')
{
$this->fileName = $fileName;
parent::__construct($fileName);
$this->_filename = $filename;
parent::__construct($filename);
}
/**
@ -62,11 +65,12 @@ class Spreadsheet_Excel_Writer extends Spreadsheet_Excel_Writer_Workbook
*/
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');
$filename = addslashes($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");
}
/**
@ -76,25 +80,25 @@ 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 $column Column for the cell to convert (0-indexed).
* @param integer $col Column for the cell to convert (0-indexed).
* @return string The cell identifier in A1 format
*/
public function rowcolToCell($row, $column)
function rowcolToCell($row, $col)
{
if ($column > 255) { //maximum column value exceeded
return new PEAR_Error('Maximum column value exceeded: ' . $column);
if ($col > 255) { //maximum column value exceeded
return new PEAR_Error("Maximum column value exceeded: $col");
}
$int = (int)($column / 26);
$frac = $column % 26;
$chr1 = '';
$int = (int)($col / 26);
$frac = $col % 26;
$chr1 = '';
if ($int > 0) {
$chr1 = chr(ord('A') + $int - 1);
}
$chr2 = chr(ord('A') + $frac);
++$row;
$row++;
return $chr1 . $chr2 . $row;
}

View File

@ -32,6 +32,10 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
if (!class_exists('PEAR')) {
require_once 'PEAR.php';
}
/**
* Class for writing Excel BIFF records.
*
@ -55,44 +59,44 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
* The BIFF/Excel version (5).
* @var integer
*/
public $BIFF_version = 0x0500;
public $_BIFF_version = 0x0500;
/**
* The byte order of this architecture. 0 => little endian, 1 => big endian
* @var integer
*/
public $byteOrder;
public $_byte_order;
/**
* The string containing the data of the BIFF stream
* @var string
*/
public $data;
public $_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
*/
public $dataSize;
public $_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()
*/
public $limit;
public $_limit;
/**
* The temporary dir for storing the OLE file
* @var string
*/
public $temporaryDirectory;
public $_tmp_dir;
/**
* The temporary file for storing the OLE file
* @var string
*/
public $temporaryFile;
public $_tmp_file;
/**
* Constructor
@ -101,13 +105,13 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
*/
public function __construct()
{
$this->byteOrder = '';
$this->data = '';
$this->dataSize = 0;
$this->limit = 2080;
$this->temporaryDirectory = '';
$this->_byte_order = '';
$this->_data = '';
$this->_datasize = 0;
$this->_limit = 2080;
$this->_tmp_dir = '';
// Set the byte order
$this->setByteOrder();
$this->_setByteOrder();
}
/**
@ -116,55 +120,51 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
*
* @access private
*/
protected function setByteOrder()
protected function _setByteOrder()
{
// Check if "pack" gives the required IEEE 64bit float
$testString = pack('d', 1.2345);
$number = pack('C8', 0x8D, 0x97, 0x6E, 0x12, 0x83, 0xC0, 0xF3, 0x3F);
if ($number == $testString) {
$teststr = pack("d", 1.2345);
$number = pack("C8", 0x8D, 0x97, 0x6E, 0x12, 0x83, 0xC0, 0xF3, 0x3F);
if ($number == $teststr) {
$byte_order = 0; // Little Endian
} elseif ($number == strrev($testString)){
} elseif ($number == strrev($teststr)){
$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->byteOrder = $byte_order;
$this->_byte_order = $byte_order;
}
/**
* General storage function
* General storage public function
*
* @param string $data binary data to prepend
* @access private
*/
protected 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);
}
/**
* General storage function
* General storage public function
*
* @param string $data binary data to append
* @access private
*/
protected 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);
}
/**
@ -175,28 +175,28 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
* 0x0010 Worksheet.
* @access private
*/
protected 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);
}
/**
@ -204,12 +204,12 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
*
* @access private
*/
protected 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);
}
/**
@ -217,23 +217,23 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
* Excel 97 the limit is 8228 bytes. Records that are longer than these limits
* must be split up into CONTINUE blocks.
*
* This function takes a long BIFF record and inserts CONTINUE records as
* This public function takes a long BIFF record and inserts CONTINUE records as
* necessary.
*
* @param string $data The original binary data to be written
* @return string A very convenient string of continue blocks
* @access private
*/
protected 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);
@ -243,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);
@ -257,13 +257,12 @@ 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
*/
protected function setTempDir($dir)
public function setTempDir($dir)
{
if (is_dir($dir)) {
$this->temporaryDirectory = $dir;
$this->_tmp_dir = $dir;
return true;
}
return false;
}
}

View File

@ -32,6 +32,10 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
if (!class_exists('PEAR')) {
require_once 'PEAR.php';
}
/**
* Class for generating Excel XF records (formats)
*
@ -42,24 +46,18 @@
class Spreadsheet_Excel_Writer_Format extends PEAR
{
/**
* The BIFF version for the workbook
* @var integer
*/
public $_BIFF_version;
/**
* Index to the FONT record.
* @var integer
*/
public $font_index;
/**
* The index given by the workbook when creating a new format.
* @var integer
*/
public $_xf_index;
/**
* Index to the FONT record.
* @var integer
*/
public $font_index;
/**
* The font name (ASCII).
* @var string
@ -250,7 +248,6 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
* Constructor
*
* @access private
* @param integer $BIFF_version
* @param integer $index the XF index for the format.
* @param array $properties array with properties to be set on initialization.
*/
@ -497,7 +494,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
@ -1103,7 +1100,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
* Sets the font family name.
*
* @access public
* @param string $font_family The font family name. Possible values are:
* @param string $fontfamily The font family name. Possible values are:
* 'Times New Roman', 'Arial', 'Courier'.
*/
public function setFontFamily($font_family)
@ -1111,4 +1108,3 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
$this->_font_name = $font_family;
}
}
?>

View File

@ -25,77 +25,81 @@
/**
* @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', '&');
define('SPREADSHEET_EXCEL_WRITER_CONCAT', "&");
if (!class_exists('PEAR')) {
require_once 'PEAR.php';
}
/**
* Class for parsing Excel formulas
@ -107,12 +111,6 @@ define('SPREADSHEET_EXCEL_WRITER_CONCAT', '&');
class Spreadsheet_Excel_Writer_Parser extends PEAR
{
/**
* The BIFF version for the workbook
* @var integer
*/
public $_BIFF_version;
/**
* The index of the character we are currently looking at
* @var integer
@ -131,11 +129,6 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
*/
public $_formula;
/**
* @var array
*/
public $_functions;
/**
* The character ahead of the current char
* @var string
@ -166,12 +159,17 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
*/
public $_references;
/**
* The BIFF version for the workbook
* @var integer
*/
public $_BIFF_version;
/**
* The class constructor
*
* @param integer $byte_order The byte order (Little endian or Big endian) of the architecture
* (optional). 1 => big endian, 0 (default) little endian.
* @param integer $biff_version
(optional). 1 => big endian, 0 (default) little endian.
*/
public function __construct($byte_order, $biff_version)
{
@ -181,14 +179,14 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
$this->_formula = ''; // The formula to parse.
$this->_lookahead = ''; // The character ahead of the current char.
$this->_parse_tree = ''; // The parse tree to be generated.
$this->_initializeHashes(); // Initialize the hashes: ptg's and function's ptg's
$this->_initializeHashes(); // Initialize the hashes: ptg's and public function's ptg's
$this->_byte_order = $byte_order; // Little Endian or Big Endian
$this->_ext_sheets = array();
$this->_references = array();
}
/**
* Initialize the ptg and function hashes.
* Initialize the ptg and public function hashes.
*
* @access private
*/
@ -296,18 +294,18 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
// Thanks to Michael Meeks and Gnumeric for the initial arg values.
//
// The following hash was generated by "function_locale.pl" in the distro.
// Refer to function_locale.pl for non-English function names.
// Refer to function_locale.pl for non-English public function names.
//
// The array elements are as follow:
// ptg: The Excel function ptg code.
// args: The number of arguments that the function takes:
// ptg: The Excel public function ptg code.
// args: The number of arguments that the public function takes:
// >=0 is a fixed number of arguments.
// -1 is a variable number of arguments.
// class: The reference, value or array class of the function args.
// vol: The function is volatile.
// class: The reference, value or array class of the public function args.
// vol: The public function is volatile.
//
$this->_functions = array(
// function ptg args class vol
// public function ptg args class vol
'COUNT' => array( 0, -1, 0, 0 ),
'IF' => array( 1, -1, 1, 0 ),
'ISNA' => array( 2, 1, 1, 0 ),
@ -603,7 +601,6 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
*
* @access private
* @param mixed $num an integer or double for conversion to its ptg value
* @return string
*/
protected function _convertNumber($num)
{
@ -643,13 +640,13 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
}
/**
* Convert a function to a ptgFunc or ptgFuncVarV depending on the number of
* Convert a public function to a ptgFunc or ptgFuncVarV depending on the number of
* args that it takes.
*
* @access private
* @param string $token The name of the function for convertion to ptg value.
* @param integer $num_args The number of arguments the function receives.
* @return string The packed ptg for the function
* @param string $token The name of the public function for convertion to ptg value.
* @param integer $num_args The number of arguments the public function receives.
* @return string The packed ptg for the public function
*/
protected function _convertFunction($token, $num_args)
{
@ -667,13 +664,11 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
}
/**
* Convert an Excel range such as A1:D4 to a ptgRefV.
*
* @access private
* @param string $range An Excel range in the A1:A2 or A1..A2 format.
* @param int $class
* @return array|string
*/
* Convert an Excel range such as A1:D4 to a ptgRefV.
*
* @access private
* @param string $range An Excel range in the A1:A2 or A1..A2 format.
*/
protected function _convertRange2d($range, $class=0)
{
@ -1276,7 +1271,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
{
return $token;
}
// if it's a function call
// if it's a public function call
elseif (preg_match("/^[A-Z0-9\xc0-\xdc\.]+$/i",$token) and ($this->_lookahead == "("))
{
return $token;
@ -1422,7 +1417,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
}
/**
* This function just introduces a ptgParen element in the tree, so that Excel
* This public function just introduces a ptgParen element in the tree, so that Excel
* doesn't get confused when working with a parenthesized formula afterwards.
*
* @access private
@ -1541,7 +1536,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
$this->_advance();
return $result;
}
// if it's a function call
// if it's a public function call
elseif (preg_match("/^[A-Z0-9\xc0-\xdc\.]+$/i",$this->_current_token))
{
$result = $this->_func();
@ -1553,7 +1548,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
}
/**
* It parses a function call. It assumes the following rule:
* It parses a public function call. It assumes the following rule:
* Func -> ( Expr [,Expr]* )
*
* @access private
@ -1575,7 +1570,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
$this->_advance(); // eat the "," or ";"
} else {
return $this->raiseError("Syntax error: comma expected in ".
"function $function, arg #{$num_args}");
"public function $function, arg #{$num_args}");
}
$result2 = $this->_condition();
if (PEAR::isError($result2)) {
@ -1597,7 +1592,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
$args = $this->_functions[$function][1];
// If fixed number of args eg. TIME($i,$j,$k). Check that the number of args is valid.
if (($args >= 0) and ($args != $num_args)) {
return $this->raiseError("Incorrect number of arguments in function $function() ");
return $this->raiseError("Incorrect number of arguments in public function $function() ");
}
$result = $this->_createTree($function, $result, $num_args);
@ -1679,14 +1674,14 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
}
$polish .= $converted_tree;
}
// if it's a function convert it here (so we can set it's arguments)
// if it's a public function convert it here (so we can set it's arguments)
if (preg_match("/^[A-Z0-9\xc0-\xdc\.]+$/",$tree['value']) and
!preg_match('/^([A-Ia-i]?[A-Za-z])(\d+)$/',$tree['value']) and
!preg_match("/^[A-Ia-i]?[A-Za-z](\d+)\.\.[A-Ia-i]?[A-Za-z](\d+)$/",$tree['value']) and
!is_numeric($tree['value']) and
!isset($this->ptg[$tree['value']]))
{
// left subtree for a function is always an array.
// left subtree for a public function is always an array.
if ($tree['left'] != '') {
$left_tree = $this->toReversePolish($tree['left']);
} else {
@ -1707,4 +1702,3 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
return $polish;
}
}
?>

View File

@ -22,19 +22,21 @@
* 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)
@ -148,7 +150,7 @@ class Spreadsheet_Excel_Writer_Validator
return true;
}
public function _getOptions()
protected function _getOptions()
{
$options = $this->_type;
$options |= $this->_style << 3;
@ -172,7 +174,7 @@ class Spreadsheet_Excel_Writer_Validator
return $options;
}
public function _getData()
protected function _getData()
{
$title_prompt_len = strlen($this->_title_prompt);
$descr_prompt_len = strlen($this->_descr_prompt);
@ -224,5 +226,3 @@ class Spreadsheet_Excel_Writer_Validator
//$this->_formula1 = ...;
}
}*/
?>

File diff suppressed because it is too large Load Diff

View File

@ -32,8 +32,10 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
require_once __DIR__ . '/Parser.php';
require_once __DIR__ . '/BIFFwriter.php';
if (!class_exists('Spreadsheet_Excel_Writer_BIFFwriter')) {
require_once 'Spreadsheet/Excel/Writer/Parser.php';
require_once 'Spreadsheet/Excel/Writer/BIFFwriter.php';
}
/**
* Class for generating Excel Spreadsheets
@ -373,49 +375,43 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
*/
public $_input_encoding;
public $activesheet;
public $firstsheet;
/**
* Constructor
*
* @param string $name The name of the new worksheet
* @param integer $index The index of the new worksheet
* @param mixed $activeSheet The current activesheet of the workbook we belong to
* @param mixed $firstSheet The first worksheet in the workbook we belong to
* @param mixed $activesheet The current activesheet of the workbook we belong to
* @param mixed $firstsheet The first worksheet in the workbook we belong to
* @param int &$str_total Reference to the total number of strings in the workbook
* @param int &$str_unique Reference to the number of unique strings in the workbook
* @param array &$str_table Reference to the array containing all the unique strings in the workbook
* @param mixed $url_format The default format for hyperlinks
* @param mixed $parser The formula parser created for the Workbook
* @param string $tmp_dir The path to the directory for temporary files
* @access private
*/
public function __construct(
$BIFF_version,
$name,
$index,
$activeSheet,
$firstSheet,
$str_total,
$str_unique,
$str_table,
$url_format,
$parser,
$tmp_dir
)
public function __construct($BIFF_version, $name,
$index, $activesheet,
$firstsheet, &$str_total,
&$str_unique, &$str_table,
$url_format, $parser,
$tmp_dir)
{
// It needs to call its parent's constructor explicitly
parent::__construct();
$this->BIFF_version = $BIFF_version;
$this->_BIFF_version = $BIFF_version;
$rowmax = 65536; // 16384 in Excel 5
$colmax = 256;
$this->name = $name;
$this->index = $index;
$this->activesheet = $activeSheet;
$this->firstsheet = $firstSheet;
$this->_str_total = $str_total;
$this->_str_unique = $str_unique;
$this->_str_table = $str_table;
$this->activesheet = $activesheet;
$this->firstsheet = $firstsheet;
// _str_total _str_unique _str_table - are actual references
// everything breaks if they're not
$this->_str_total = &$str_total;
$this->_str_unique = &$str_unique;
$this->_str_table = &$str_table;
$this->_url_format = $url_format;
$this->_parser = $parser;
@ -493,8 +489,8 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$this->_dv = array();
$this->temporaryDirectory = $tmp_dir;
$this->temporaryFile = '';
$this->_tmp_dir = $tmp_dir;
$this->_tmp_file = '';
$this->_initialize();
}
@ -512,7 +508,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
return;
}
if ($this->temporaryDirectory === '' && ini_get('open_basedir') === true) {
if ($this->_tmp_dir === '' && ini_get('open_basedir') === true) {
// open_basedir restriction in effect - store data in memory
// ToDo: Let the error actually have an effect somewhere
$this->_using_tmpfile = false;
@ -520,12 +516,12 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
}
// Open tmp file for storing Worksheet data
if ($this->temporaryDirectory === '') {
if ($this->_tmp_dir === '') {
$fh = tmpfile();
} else {
// For people with open base dir restriction
$this->temporaryFile = tempnam($this->temporaryDirectory, 'Spreadsheet_Excel_Writer');
$fh = @fopen($this->temporaryFile, 'w+b');
$this->_tmp_file = tempnam($this->_tmp_dir, "Spreadsheet_Excel_Writer");
$fh = @fopen($this->_tmp_file, "w+b");
}
if ($fh === false) {
@ -604,7 +600,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$this->_storeGridset();
// Prepend GUTS
if ($this->BIFF_version == 0x0500) {
if ($this->_BIFF_version == 0x0500) {
$this->_storeGuts();
}
@ -615,7 +611,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$this->_storePrintHeaders();
// Prepend EXTERNSHEET references
if ($this->BIFF_version == 0x0500) {
if ($this->_BIFF_version == 0x0500) {
for ($i = $num_sheets; $i > 0; $i--) {
$sheetname = $sheetnames[$i-1];
$this->_storeExternsheet($sheetname);
@ -623,7 +619,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
}
// Prepend the EXTERNCOUNT of external references.
if ($this->BIFF_version == 0x0500) {
if ($this->_BIFF_version == 0x0500) {
$this->_storeExterncount($num_sheets);
}
@ -637,7 +633,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
}
// Prepend the BOF record
$this->storeBof(0x0010);
$this->_storeBof(0x0010);
/*
* End of prepend. Read upwards from here.
@ -652,18 +648,18 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$this->_storeSelection($this->_selection);
$this->_storeMergedCells();
/* TODO: add data validity */
/*if ($this->BIFF_version == 0x0600) {
/*if ($this->_BIFF_version == 0x0600) {
$this->_storeDataValidity();
}*/
$this->storeEof();
$this->_storeEof();
if ( $this->temporaryFile != '' ) {
if ( $this->_tmp_file != '' ) {
if ( $this->_filehandle ) {
fclose($this->_filehandle);
$this->_filehandle = '';
}
@unlink($this->temporaryFile);
$this->temporaryFile = '';
@unlink($this->_tmp_file);
$this->_tmp_file = '';
$this->_using_tmpfile = true;
}
}
@ -691,9 +687,9 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$buffer = 4096;
// Return data stored in memory
if (isset($this->data)) {
$tmp = $this->data;
unset($this->data);
if (isset($this->_data)) {
$tmp = $this->_data;
unset($this->_data);
$fh = $this->_filehandle;
if ($this->_using_tmpfile) {
fseek($fh, 0);
@ -726,7 +722,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
return;
}
$max_record_ranges = floor(($this->limit - 6) / 8);
$max_record_ranges = floor(($this->_limit - 6) / 8);
if($this->_merged_cells_counter >= $max_record_ranges)
{
$this->_merged_cells_record++;
@ -813,7 +809,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
// if the new range lies WITHIN the existing range
if ($lastcol < $existing_end)
{ // split the existing range by adding a range after our new range
$this->_colinfo[] = array($lastcol+1, $existing_end, $colinfo[2], &$colinfo[3], $colinfo[4], $colinfo[5]);
$this->_colinfo[] = array($lastcol+1, $existing_end, $colinfo[2], /* format */ $colinfo[3], $colinfo[4], $colinfo[5]);
}
} // if the new range ends inside an existing range
elseif ($lastcol > $existing_start && $lastcol < $existing_end)
@ -827,7 +823,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
} // added by Dan Lynn <dan@spiderweblabs.com) on 2006-12-06
// regenerate keys
$this->_colinfo = array_values($this->_colinfo);
$this->_colinfo[] = array($firstcol, $lastcol, $width, &$format, $hidden, $level);
$this->_colinfo[] = array($firstcol, $lastcol, $width, $format, $hidden, $level);
// Set width to zero if column is hidden
$width = ($hidden) ? 0 : $width;
for ($col = $firstcol; $col <= $lastcol; $col++)
@ -1192,7 +1188,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
{
// Confine the scale to Excel's range
if ($scale < 10 || $scale > 400) {
$this->raiseError('Zoom factor ' . $scale . ' outside range: 10 <= zoom <= 400');
$this->raiseError("Zoom factor $scale outside range: 10 <= zoom <= 400");
$scale = 100;
}
@ -1349,13 +1345,13 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
{
if ($this->_using_tmpfile) {
// Add CONTINUE records if necessary
if (strlen($data) > $this->limit) {
$data = $this->addContinue($data);
if (strlen($data) > $this->_limit) {
$data = $this->_addContinue($data);
}
fwrite($this->_filehandle, $data);
$this->dataSize += strlen($data);
$this->_datasize += strlen($data);
} else {
parent::append($data);
parent::_append($data);
}
}
@ -1541,7 +1537,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$header = pack("vv", $record, $length);
$data = pack("vvv", $row, $col, $xf);
$xl_double = pack("d", $num);
if ($this->byteOrder) { // if it's Big Endian
if ($this->_byte_order) { // if it's Big Endian
$xl_double = strrev($xl_double);
}
@ -1566,7 +1562,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
*/
public function writeString($row, $col, $str, $format = null)
{
if ($this->BIFF_version == 0x0600) {
if ($this->_BIFF_version == 0x0600) {
return $this->writeStringBIFF8($row, $col, $str, $format);
}
$strlen = strlen($str);
@ -1927,7 +1923,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
/**
* This is the more general form of writeUrl(). It allows a hyperlink to be
* written to a range of cells. This function also decides the type of hyperlink
* written to a range of cells. This public function also decides the type of hyperlink
* to be written. These are either, Web (http, ftp, mailto), Internal
* (Sheet1!A1) or external ('c:\temp\foo.xls#Sheet1!A1').
*
@ -2291,17 +2287,17 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$col_max = $this->_dim_colmax + 1; // Last column plus 1
$reserved = 0x0000; // Reserved by Excel
if ($this->BIFF_version == 0x0500) {
if ($this->_BIFF_version == 0x0500) {
$length = 0x000A; // Number of bytes to follow
$data = pack("vvvvv", $row_min, $row_max,
$col_min, $col_max, $reserved);
} elseif ($this->BIFF_version == 0x0600) {
} elseif ($this->_BIFF_version == 0x0600) {
$length = 0x000E;
$data = pack("VVvvv", $row_min, $row_max,
$col_min, $col_max, $reserved);
}
$header = pack("vv", $record, $length);
$this->prepend($header.$data);
$this->_prepend($header.$data);
}
/**
@ -2312,9 +2308,9 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
protected function _storeWindow2()
{
$record = 0x023E; // Record identifier
if ($this->BIFF_version == 0x0500) {
if ($this->_BIFF_version == 0x0500) {
$length = 0x000A; // Number of bytes to follow
} elseif ($this->BIFF_version == 0x0600) {
} elseif ($this->_BIFF_version == 0x0600) {
$length = 0x0012;
}
@ -2351,10 +2347,10 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$header = pack("vv", $record, $length);
$data = pack("vvv", $grbit, $rwTop, $colLeft);
// FIXME !!!
if ($this->BIFF_version == 0x0500) {
if ($this->_BIFF_version == 0x0500) {
$rgbHdr = 0x00000000; // Row/column heading and gridline color
$data .= pack("V", $rgbHdr);
} elseif ($this->BIFF_version == 0x0600) {
} elseif ($this->_BIFF_version == 0x0600) {
$rgbHdr = 0x0040; // Row/column heading and gridline color index
$zoom_factor_page_break = 0x0000;
$zoom_factor_normal = 0x0000;
@ -2376,7 +2372,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$header = pack("vv", $record, $length);
$data = pack("v", $colwidth);
$this->prepend($header . $data);
$this->_prepend($header . $data);
}
/**
@ -2437,7 +2433,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$header = pack("vv", $record, $length);
$data = pack("vvvvvC", $colFirst, $colLast, $coldx,
$ixfe, $grbit, $reserved);
$this->prepend($header.$data);
$this->_prepend($header.$data);
}
/**
@ -2527,7 +2523,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$header = pack("vv", $record, $length);
$data = pack("v", $count);
$this->prepend($header . $data);
$this->_prepend($header . $data);
}
/**
@ -2559,7 +2555,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$header = pack("vv", $record, $length);
$data = pack("CC", $cch, $rgch);
$this->prepend($header . $data . $sheetname);
$this->_prepend($header . $data . $sheetname);
}
/**
@ -2685,7 +2681,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$numHdr = pack("d", $numHdr);
$numFtr = pack("d", $numFtr);
if ($this->byteOrder) { // if it's Big Endian
if ($this->_byte_order) { // if it's Big Endian
$numHdr = strrev($numHdr);
$numFtr = strrev($numFtr);
}
@ -2701,7 +2697,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$iVRes);
$data2 = $numHdr.$numFtr;
$data3 = pack("v", $iCopies);
$this->prepend($header . $data1 . $data2 . $data3);
$this->_prepend($header . $data1 . $data2 . $data3);
}
/**
@ -2715,7 +2711,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$str = $this->_header; // header string
$cch = strlen($str); // Length of header string
if ($this->BIFF_version == 0x0600) {
if ($this->_BIFF_version == 0x0600) {
$encoding = 0x0; // TODO: Unicode support
$length = 3 + $cch; // Bytes to follow
} else {
@ -2723,13 +2719,13 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
}
$header = pack("vv", $record, $length);
if ($this->BIFF_version == 0x0600) {
if ($this->_BIFF_version == 0x0600) {
$data = pack("vC", $cch, $encoding);
} else {
$data = pack("C", $cch);
}
$this->prepend($header.$data.$str);
$this->_prepend($header.$data.$str);
}
/**
@ -2743,7 +2739,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$str = $this->_footer; // Footer string
$cch = strlen($str); // Length of footer string
if ($this->BIFF_version == 0x0600) {
if ($this->_BIFF_version == 0x0600) {
$encoding = 0x0; // TODO: Unicode support
$length = 3 + $cch; // Bytes to follow
} else {
@ -2751,13 +2747,13 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
}
$header = pack("vv", $record, $length);
if ($this->BIFF_version == 0x0600) {
if ($this->_BIFF_version == 0x0600) {
$data = pack("vC", $cch, $encoding);
} else {
$data = pack("C", $cch);
}
$this->prepend($header . $data . $str);
$this->_prepend($header . $data . $str);
}
/**
@ -2775,7 +2771,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$header = pack("vv", $record, $length);
$data = pack("v", $fHCenter);
$this->prepend($header.$data);
$this->_prepend($header.$data);
}
/**
@ -2792,7 +2788,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$header = pack("vv", $record, $length);
$data = pack("v", $fVCenter);
$this->prepend($header . $data);
$this->_prepend($header . $data);
}
/**
@ -2809,11 +2805,11 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$header = pack("vv", $record, $length);
$data = pack("d", $margin);
if ($this->byteOrder) { // if it's Big Endian
if ($this->_byte_order) { // if it's Big Endian
$data = strrev($data);
}
$this->prepend($header . $data);
$this->_prepend($header . $data);
}
/**
@ -2830,11 +2826,11 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$header = pack("vv", $record, $length);
$data = pack("d", $margin);
if ($this->byteOrder) { // if it's Big Endian
if ($this->_byte_order) { // if it's Big Endian
$data = strrev($data);
}
$this->prepend($header . $data);
$this->_prepend($header . $data);
}
/**
@ -2851,11 +2847,11 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$header = pack("vv", $record, $length);
$data = pack("d", $margin);
if ($this->byteOrder) { // if it's Big Endian
if ($this->_byte_order) { // if it's Big Endian
$data = strrev($data);
}
$this->prepend($header . $data);
$this->_prepend($header . $data);
}
/**
@ -2872,11 +2868,11 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$header = pack("vv", $record, $length);
$data = pack("d", $margin);
if ($this->byteOrder) { // if it's Big Endian
if ($this->_byte_order) { // if it's Big Endian
$data = strrev($data);
}
$this->prepend($header . $data);
$this->_prepend($header . $data);
}
/**
@ -2926,7 +2922,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$header = pack("vv", $record, $length);
$data = pack("v", $fPrintRwCol);
$this->prepend($header . $data);
$this->_prepend($header . $data);
}
/**
@ -2944,7 +2940,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$header = pack("vv", $record, $length);
$data = pack("v", $fPrintGrid);
$this->prepend($header . $data);
$this->_prepend($header . $data);
}
/**
@ -2962,7 +2958,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$header = pack("vv", $record, $length);
$data = pack("v", $fGridSet);
$this->prepend($header . $data);
$this->_prepend($header . $data);
}
/**
@ -3008,7 +3004,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$header = pack("vv", $record, $length);
$data = pack("vvvv", $dxRwGut, $dxColGut, $row_level, $col_level);
$this->prepend($header.$data);
$this->_prepend($header.$data);
}
@ -3052,7 +3048,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$header = pack("vv", $record, $length);
$data = pack("v", $grbit);
$this->prepend($header . $data);
$this->_prepend($header . $data);
}
/**
@ -3076,7 +3072,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$record = 0x001b; // Record identifier
$cbrk = count($breaks); // Number of page breaks
if ($this->BIFF_version == 0x0600) {
if ($this->_BIFF_version == 0x0600) {
$length = 2 + 6*$cbrk; // Bytes to follow
} else {
$length = 2 + 2*$cbrk; // Bytes to follow
@ -3087,14 +3083,14 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
// Append each page break
foreach ($breaks as $break) {
if ($this->BIFF_version == 0x0600) {
if ($this->_BIFF_version == 0x0600) {
$data .= pack("vvv", $break, 0x0000, 0x00ff);
} else {
$data .= pack("v", $break);
}
}
$this->prepend($header.$data);
$this->_prepend($header.$data);
}
@ -3122,7 +3118,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$record = 0x001a; // Record identifier
$cbrk = count($breaks); // Number of page breaks
if ($this->BIFF_version == 0x0600) {
if ($this->_BIFF_version == 0x0600) {
$length = 2 + 6*$cbrk; // Bytes to follow
} else {
$length = 2 + 2*$cbrk; // Bytes to follow
@ -3133,14 +3129,14 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
// Append each page break
foreach ($breaks as $break) {
if ($this->BIFF_version == 0x0600) {
if ($this->_BIFF_version == 0x0600) {
$data .= pack("vvv", $break, 0x0000, 0xffff);
} else {
$data .= pack("v", $break);
}
}
$this->prepend($header . $data);
$this->_prepend($header . $data);
}
/**
@ -3163,7 +3159,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$header = pack("vv", $record, $length);
$data = pack("v", $fLock);
$this->prepend($header.$data);
$this->_prepend($header.$data);
}
/**
@ -3186,7 +3182,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$header = pack("vv", $record, $length);
$data = pack("v", $wPassword);
$this->prepend($header . $data);
$this->_prepend($header . $data);
}
@ -3254,7 +3250,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
* The width and height of the cells are also variable and have to be taken into
* account.
* The values of $col_start and $row_start are passed in from the calling
* function. The values of $col_end and $row_end are calculated by subtracting
* public function. The values of $col_end and $row_end are calculated by subtracting
* the width and height of the bitmap from the width and height of the
* underlying cells.
* The vertices are expressed as a percentage of the underlying cell width as
@ -3609,4 +3605,3 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
}
}
}
?>

View File

@ -23,8 +23,12 @@
],
"autoload": {
"psr-0": {
"Spreadsheet": "./",
"Test": "./test"
"Spreadsheet": ""
}
},
"autoload-dev": {
"psr-0": {
"Test": "test"
}
},
"description": "More info available on: http://pear.php.net/package/Spreadsheet_Excel_Writer",

View File

@ -1,4 +1,4 @@
<phpunit bootstrap="test/bootstrap.php"
<phpunit bootstrap="vendor/autoload.php"
cacheTokens="false"
colors="true"
convertErrorsToExceptions="true"
@ -14,4 +14,15 @@
<directory>test/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">Spreadsheet/</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<log type="coverage-text" target="php://stdout"/>
</logging>
</phpunit>

View File

@ -1,17 +0,0 @@
<?php
/**
* @author stev leibelt <artodeto@bazzline.net>
* @since 2016-01-17
*/
class Test_Spreadsheet_Excel_WriterTestCase extends PHPUnit_Framework_TestCase
{
/**
* @param string $fileName
* @return Spreadsheet_Excel_Writer_Workbook
*/
protected function getNewWorkbook($fileName = 'my_workbook')
{
return new Spreadsheet_Excel_Writer_Workbook($fileName);
}
}

View File

@ -1,15 +0,0 @@
<?php
/**
* @author stev leibelt <artodeto@bazzline.net>
* @since 2016-01-17
*/
class Test_Spreadsheet_Excel_Writer_WorkbookTest extends Test_Spreadsheet_Excel_WriterTestCase
{
public function testSetVersion()
{
$workbook = $this->getNewWorkbook();
$workbook->setVersion(8);
}
}

View File

@ -0,0 +1,75 @@
<?php
/**
* @author stev leibelt <artodeto@bazzline.net>
* @since 2016-01-17
*/
class Test_Spreadsheet_Excel_Writer_WorkbookTest extends Test_Spreadsheet_Excel_WriterTestCase
{
public function testSetVersion()
{
$workbook = $this->getNewWorkbook();
$before = get_object_vars($workbook);
$workbook->setVersion(1);
$this->assertEquals($before, get_object_vars($workbook), "Version 1 should not change internal state");
$workbook->setVersion(8);
$this->assertNotEquals($before, get_object_vars($workbook), "Version 8 should change internal state");
return $workbook;
}
/**
* @depends testSetVersion
*/
public function testWriteSingleCell(Spreadsheet_Excel_Writer $workbook)
{
$sheet = $workbook->addWorksheet("Example");
$sheet->write(0, 0, "Example");
$this->assertSameAsInFixture('example.xls', $workbook);
}
public function testWriteWithFormat()
{
$workbook = $this->getNewWorkbook();
$workbook->setVersion(8);
$format = $workbook->addFormat();
$format->setFontFamily('Helvetica');
$format->setSize(16);
$format->setVAlign('vcenter');
$format->setBorder(1);
$sheet = $workbook->addWorksheet('Example report');
$sheet->setInputEncoding('utf-8');
$sheet->setColumn(0, 10, 35);
$sheet->writeString(0, 0, "Test string", $format);
$sheet->setRow(0, 40);
$sheet->writeString(1, 0, "こんにちわ");
$this->assertSameAsInFixture('with_format.xls', $workbook);
}
public function testWithDefaultVersion()
{
$workbook = $this->getNewWorkbook();
$sheet = $workbook->addWorksheet("Example");
for ($i = 0; $i < 10; $i++) {
for ($j = 0; $j < 10; $j++) {
$sheet->write($i, $j, "Row $i $j");
}
}
$this->assertSameAsInFixture('example2.xls', $workbook);
}
}

View File

@ -0,0 +1,55 @@
<?php
/**
* @author stev leibelt <artodeto@bazzline.net>
* @since 2016-01-17
*/
class Test_Spreadsheet_Excel_WriterTestCase extends PHPUnit_Framework_TestCase
{
const FIXTURES_PATH = 'test/fixture/';
/**
* @param string $filename
* @return Spreadsheet_Excel_Writer
*/
protected function getNewWorkbook($filename = '')
{
// we're writing to the standard output by defaulr
return new Spreadsheet_Excel_Writer($filename);
}
protected function assertSameAsInFixture($filename, Spreadsheet_Excel_Writer $workbook)
{
$this->assertEmpty($workbook->_filename, "Testing with fixtures works only for standard output");
// we have to fix timestamp for fixtures to work
$workbook->_timestamp = 1000000000; // somewhere in 2001
ob_start();
$workbook->close();
$data = ob_get_clean();
$fullPath = self::FIXTURES_PATH.$filename;
if ($this->shouldUpdateFixtures()) {
file_put_contents($fullPath, $data);
}
if (!is_file($fullPath)) {
$this->fail("Fixture $filename not found");
}
// TODO: should we save data for future analysis?
//file_put_contents("{$fullPath}.work", $data);
$this->assertEquals(file_get_contents($fullPath), $data, "Output differs for $filename");
}
/**
* We should update golden files
*/
private function shouldUpdateFixtures()
{
return isset($_SERVER['GOLDEN']);
}
}

View File

@ -1,4 +0,0 @@
<?php
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/Test/Spreadsheet/Excel/Writer/Test_Spreadsheet_Excel_WriterTestCase.php'; //@todo fix this

BIN
test/fixture/example.xls Normal file

Binary file not shown.

BIN
test/fixture/example2.xls Normal file

Binary file not shown.

Binary file not shown.