ws cosmetics.

git-svn-id: https://svn.php.net/repository/pear/packages/Spreadsheet_Excel_Writer/trunk@197024 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Helgi Þormar Þorbjörnsson 2005-09-27 07:33:54 +00:00
parent e4b8fe22f3
commit db20068031
8 changed files with 646 additions and 646 deletions

View File

@ -4,7 +4,7 @@
*
* PERL Spreadsheet::WriteExcel module.
*
* The author of the Spreadsheet::WriteExcel module is John McNamara
* The author of the Spreadsheet::WriteExcel module is John McNamara
* <jmcnamara@cpan.org>
*
* I _DO_ maintain this code, and John McNamara has nothing to do with the
@ -86,18 +86,18 @@ class Spreadsheet_Excel_Writer extends Spreadsheet_Excel_Writer_Workbook
if ($col > 255) { //maximum column value exceeded
return new PEAR_Error("Maximum column value exceeded: $col");
}
$int = (int)($col / 26);
$frac = $col % 26;
$chr1 = '';
if ($int > 0) {
$chr1 = chr(ord('A') + $int - 1);
}
$chr2 = chr(ord('A') + $frac);
$row++;
return $chr1.$chr2.$row;
}
}

View File

@ -5,7 +5,7 @@
* The majority of this is _NOT_ my code. I simply ported it from the
* PERL Spreadsheet::WriteExcel module.
*
* The author of the Spreadsheet::WriteExcel module is John McNamara
* The author of the Spreadsheet::WriteExcel module is John McNamara
* <jmcnamara@cpan.org>
*
* I _DO_ maintain this code, and John McNamara has nothing to do with the
@ -36,14 +36,14 @@ require_once 'PEAR.php';
/**
* Class for writing Excel BIFF records.
*
*
* From "MICROSOFT EXCEL BINARY FILE FORMAT" by Mark O'Brien (Microsoft Corporation):
*
* BIFF (BInary File Format) is the file format in which Excel documents are
* BIFF (BInary File Format) is the file format in which Excel documents are
* saved on disk. A BIFF file is a complete description of an Excel document.
* BIFF files consist of sequences of variable-length records. There are many
* different types of BIFF records. For example, one record type describes a
* formula entered into a cell; one describes the size and location of a
* BIFF files consist of sequences of variable-length records. There are many
* different types of BIFF records. For example, one record type describes a
* formula entered into a cell; one describes the size and location of a
* window into a document; another describes a picture format.
*
* @author Xavier Noguer <xnoguer@php.net>
@ -54,13 +54,13 @@ require_once 'PEAR.php';
class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
{
/**
* The BIFF/Excel version (5).
* The BIFF/Excel version (5).
* @var integer
*/
var $_BIFF_version = 0x0500;
/**
* The byte order of this architecture. 0 => little endian, 1 => big endian
* The byte order of this architecture. 0 => little endian, 1 => big endian
* @var integer
*/
var $_byte_order;
@ -83,7 +83,7 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
* @see _addContinue()
*/
var $_limit;
/**
* Constructor
*
@ -94,7 +94,7 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
$this->_byte_order = '';
$this->_data = '';
$this->_datasize = 0;
$this->_limit = 2080;
$this->_limit = 2080;
// Set the byte order
$this->_setByteOrder();
}
@ -178,7 +178,7 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
$year = 0x07CC;
}
$version = $this->_BIFF_version;
$header = pack("vv", $record, $length);
$data = pack("vvvv", $version, $type, $build, $year);
$this->_prepend($header.$data.$unknown);
@ -189,7 +189,7 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
*
* @access private
*/
function _storeEof()
function _storeEof()
{
$record = 0x000A; // Record identifier
$length = 0x0000; // Number of bytes to follow
@ -213,24 +213,24 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
{
$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);
$header = pack("vv", $record, $limit); // Headers for continue records
// Retrieve chunks of 2080/8224 bytes +4 for the header.
for ($i = $limit; $i < strlen($data) - $limit; $i += $limit) {
$tmp .= $header;
$tmp .= substr($data, $i, $limit);
}
// Retrieve the last chunk of data
$header = pack("vv", $record, strlen($data) - $i);
$tmp .= $header;
$tmp .= substr($data, $i, strlen($data) - $i);
return $tmp;
}
}

View File

@ -5,7 +5,7 @@
* The majority of this is _NOT_ my code. I simply ported it from the
* PERL Spreadsheet::WriteExcel module.
*
* The author of the Spreadsheet::WriteExcel module is John McNamara
* The author of the Spreadsheet::WriteExcel module is John McNamara
* <jmcnamara@cpan.org>
*
* I _DO_ maintain this code, and John McNamara has nothing to do with the
@ -266,9 +266,9 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
$this->_font_script = 0;
$this->_font_family = 0;
$this->_font_charset = 0;
$this->_num_format = 0;
$this->_hidden = 0;
$this->_locked = 0;
@ -282,19 +282,19 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
$this->_bg_color = 0x41;
$this->_pattern = 0;
$this->_bottom = 0;
$this->_top = 0;
$this->_left = 0;
$this->_right = 0;
$this->_diag = 0;
$this->_bottom_color = 0x40;
$this->_top_color = 0x40;
$this->_left_color = 0x40;
$this->_right_color = 0x40;
$this->_diag_color = 0x40;
// Set properties passed to Spreadsheet_Excel_Writer_Workbook::addFormat()
foreach ($properties as $property => $value)
{
@ -321,7 +321,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
$style = $this->_locked;
$style |= $this->_hidden << 1;
}
// Flags to indicate if attributes have been set.
$atr_num = ($this->_num_format != 0)?1:0;
$atr_fnt = ($this->font_index != 0)?1:0;
@ -334,7 +334,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
($this->_bg_color != 0x41) ||
$this->_pattern)?1:0;
$atr_prot = $this->_locked | $this->_hidden;
// Zero the default border colour if the border has not been set.
if ($this->_bottom == 0) {
$this->_bottom_color = 0;
@ -351,7 +351,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
if ($this->_diag == 0) {
$this->_diag_color = 0;
}
$record = 0x00E0; // Record identifier
if ($this->_BIFF_version == 0x0500) {
$length = 0x0010; // Number of bytes to follow
@ -359,7 +359,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
if ($this->_BIFF_version == 0x0600) {
$length = 0x0014;
}
$ifnt = $this->font_index; // Index to FONT record
$ifmt = $this->_num_format; // Index to FORMAT record
if ($this->_BIFF_version == 0x0500) {
@ -374,22 +374,22 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
$align |= $atr_bdr << 13;
$align |= $atr_pat << 14;
$align |= $atr_prot << 15;
$icv = $this->_fg_color; // fg and bg pattern colors
$icv |= $this->_bg_color << 7;
$fill = $this->_pattern; // Fill and border line style
$fill |= $this->_bottom << 6;
$fill |= $this->_bottom_color << 9;
$border1 = $this->_top; // Border line style and color
$border1 |= $this->_left << 3;
$border1 |= $this->_right << 6;
$border1 |= $this->_top_color << 9;
$border2 = $this->_left_color; // Border color
$border2 |= $this->_right_color << 7;
$header = pack("vv", $record, $length);
$data = pack("vvvvvvvv", $ifnt, $ifmt, $style, $align,
$icv, $fill,
@ -409,7 +409,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
$icv = $this->_fg_color; // fg and bg pattern colors
$icv |= $this->_bg_color << 7;
$border1 = $this->_left; // Border line style and color
$border1 |= $this->_right << 4;
$border1 |= $this->_top << 8;
@ -420,7 +420,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
$diag_tr_to_lb = 0; // FIXME: add method
$border1 |= $diag_tl_to_rb << 30;
$border1 |= $diag_tr_to_lb << 31;
$border2 = $this->_top_color; // Border color
$border2 |= $this->_bottom_color << 7;
$border2 |= $this->_diag_color << 14;
@ -438,7 +438,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
return($header.$data);
}
/**
* Generate an Excel BIFF FONT record.
*
@ -454,7 +454,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
$bFamily = $this->_font_family; // Font family
$bCharSet = $this->_font_charset; // Character set
$encoding = 0; // TODO: Unicode support
$cch = strlen($this->_font_name); // Length of font name
$record = 0x31; // Record identifier
if ($this->_BIFF_version == 0x0500) {
@ -476,7 +476,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
if ($this->_font_shadow) {
$grbit |= 0x20;
}
$header = pack("vv", $record, $length);
if ($this->_BIFF_version == 0x0500) {
$data = pack("vvvvvCCCCC", $dyHeight, $grbit, $icv, $bls,
@ -489,9 +489,9 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
}
return($header . $data. $this->_font_name);
}
/**
* Returns a unique hash key for a font.
* Returns a unique hash key for a font.
* Used by Spreadsheet_Excel_Writer_Workbook::_storeAllFonts()
*
* The elements that form the key are arranged to increase the probability of
@ -510,7 +510,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
$key = str_replace(" ","_",$key);
return ($key);
}
/**
* Returns the index used by Spreadsheet_Excel_Writer_Worksheet::_XF()
*
@ -520,7 +520,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
{
return($this->_xf_index);
}
/**
* Used in conjunction with the set_xxx_color methods to convert a color
* string into a number. Color range is 0..63 but we will restrict it
@ -552,36 +552,36 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
'white' => 0x09,
'yellow' => 0x0D
);
// Return the default color, 0x7FFF, if undef,
if ($name_color == '') {
return(0x7FFF);
}
// or the color string converted to an integer,
if (isset($colors[$name_color])) {
return($colors[$name_color]);
}
// or the default color if string is unrecognised,
if (preg_match("/\D/",$name_color)) {
return(0x7FFF);
}
// or an index < 8 mapped into the correct range,
if ($name_color < 8) {
return($name_color + 8);
}
// or the default color if arg is outside range,
if ($name_color > 63) {
return(0x7FFF);
}
// or an integer in the valid range
return($name_color);
}
/**
* Set cell alignment.
*
@ -593,9 +593,9 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
if (preg_match("/\d/",$location)) {
return; // Ignore numbers
}
$location = strtolower($location);
if ($location == 'left') {
$this->_text_h_align = 1;
}
@ -639,7 +639,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
$this->_text_v_align = 4;
}
}
/**
* This is an alias for the unintuitive setAlign('merge')
*
@ -649,7 +649,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
{
$this->setAlign('merge');
}
/**
* Sets the boldness of the text.
* Bold has a range 100..1000.
@ -676,12 +676,12 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
}
$this->_bold = $weight;
}
/************************************
* FUNCTIONS FOR SETTING CELLS BORDERS
*/
/**
* Sets the width for the bottom border of the cell
*
@ -692,7 +692,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
{
$this->_bottom = $style;
}
/**
* Sets the width for the top border of the cell
*
@ -703,7 +703,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
{
$this->_top = $style;
}
/**
* Sets the width for the left border of the cell
*
@ -714,7 +714,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
{
$this->_left = $style;
}
/**
* Sets the width for the right border of the cell
*
@ -725,8 +725,8 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
{
$this->_right = $style;
}
/**
* Set cells borders to the same style
*
@ -740,17 +740,17 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
$this->setLeft($style);
$this->setRight($style);
}
/*******************************************
* FUNCTIONS FOR SETTING CELLS BORDERS COLORS
*/
/**
* Sets all the cell's borders to the same color
*
* @access public
* @param mixed $color The color we are setting. Either a string (like 'blue'),
* @param mixed $color The color we are setting. Either a string (like 'blue'),
* or an integer (range is [8...63]).
*/
function setBorderColor($color)
@ -760,7 +760,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
$this->setLeftColor($color);
$this->setRightColor($color);
}
/**
* Sets the cell's bottom border color
*
@ -772,7 +772,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
$value = $this->_getColor($color);
$this->_bottom_color = $value;
}
/**
* Sets the cell's top border color
*
@ -784,7 +784,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
$value = $this->_getColor($color);
$this->_top_color = $value;
}
/**
* Sets the cell's left border color
*
@ -796,7 +796,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
$value = $this->_getColor($color);
$this->_left_color = $value;
}
/**
* Sets the cell's right border color
*
@ -808,8 +808,8 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
$value = $this->_getColor($color);
$this->_right_color = $value;
}
/**
* Sets the cell's foreground color
*
@ -824,7 +824,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
$this->_pattern = 1;
}
}
/**
* Sets the cell's background color
*
@ -839,7 +839,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
$this->_pattern = 1;
}
}
/**
* Sets the cell's color
*
@ -851,7 +851,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
$value = $this->_getColor($color);
$this->_color = $value;
}
/**
* Sets the fill pattern attribute of a cell
*
@ -863,7 +863,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
{
$this->_pattern = $arg;
}
/**
* Sets the underline of the text
*
@ -875,7 +875,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
{
$this->_underline = $underline;
}
/**
* Sets the font style as italic
*
@ -887,7 +887,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
}
/**
* Sets the font size
* Sets the font size
*
* @access public
* @param integer $size The font size (in pixels I think).
@ -896,7 +896,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
{
$this->_size = $size;
}
/**
* Sets text wrapping
*

View File

@ -5,7 +5,7 @@
* The majority of this is _NOT_ my code. I simply ported it from the
* PERL Spreadsheet::WriteExcel module.
*
* The author of the Spreadsheet::WriteExcel module is John McNamara
* The author of the Spreadsheet::WriteExcel module is John McNamara
* <jmcnamara@cpan.org>
*
* I _DO_ maintain this code, and John McNamara has nothing to do with the
@ -130,7 +130,7 @@ class Spreadsheet_Excel_Writer_OLEwriter extends PEAR
function _initialize()
{
$OLEfile = $this->_OLEfilename;
if (($OLEfile == '-') or ($OLEfile == '')) {
$this->_tmp_filename = tempnam("/tmp", "OLEwriter");
$fh = fopen($this->_tmp_filename, "wb");
@ -144,7 +144,7 @@ class Spreadsheet_Excel_Writer_OLEwriter extends PEAR
$this->raiseError("Can't open $OLEfile. It may be in use or protected.");
}
}
// Store filehandle
$this->_filehandle = $fh;
}
@ -165,11 +165,11 @@ class Spreadsheet_Excel_Writer_OLEwriter extends PEAR
function setSize($biffsize)
{
$maxsize = 7087104; // TODO: extend max size
if ($biffsize > $maxsize) {
$this->raiseError("Maximum file size, $maxsize, exceeded.");
}
$this->_biffsize = $biffsize;
// Set the min file size to 4k to avoid having to use small blocks
if ($biffsize > 4096) {
@ -209,13 +209,13 @@ class Spreadsheet_Excel_Writer_OLEwriter extends PEAR
* @access public
* @see Spreadsheet_Excel_Writer_Workbook::store_OLE_file()
*/
function close()
function close()
{
//return if not $this->{_size_allowed};
$this->_writePadding();
$this->_writePropertyStorage();
$this->_writeBigBlockDepot();
// Close the filehandle
// Close the filehandle
fclose($this->_filehandle);
if (($this->_OLEfilename == '-') or ($this->_OLEfilename == '')) {
$fh = fopen($this->_tmp_filename, "rb");
@ -260,7 +260,7 @@ class Spreadsheet_Excel_Writer_OLEwriter extends PEAR
$sbd_startblock = pack("V", -2);
$unknown7 = pack("VVV", 0x00, -2 ,0x00);
$unused = pack("V", -1);
fwrite($this->_filehandle, $id);
fwrite($this->_filehandle, $unknown1);
fwrite($this->_filehandle, $unknown2);
@ -272,7 +272,7 @@ class Spreadsheet_Excel_Writer_OLEwriter extends PEAR
fwrite($this->_filehandle, $unknown6);
fwrite($this->_filehandle, $sbd_startblock);
fwrite($this->_filehandle, $unknown7);
for ($i=1; $i <= $num_lists; $i++) {
$root_start++;
fwrite($this->_filehandle, pack("V",$root_start));
@ -294,11 +294,11 @@ class Spreadsheet_Excel_Writer_OLEwriter extends PEAR
$num_lists = $this->_list_blocks;
$total_blocks = $num_lists *128;
$used_blocks = $num_blocks + $num_lists +2;
$marker = pack("V", -3);
$end_of_chain = pack("V", -2);
$unused = pack("V", -1);
for ($i=1; $i < $num_blocks; $i++) {
fwrite($this->_filehandle, pack("V",$i));
}
@ -341,7 +341,7 @@ class Spreadsheet_Excel_Writer_OLEwriter extends PEAR
{
$length = 0;
$rawname = '';
if ($name != '') {
$name = $name . "\0";
for ($i = 0; $i < strlen($name); $i++) {
@ -350,24 +350,24 @@ class Spreadsheet_Excel_Writer_OLEwriter extends PEAR
}
$length = strlen($name) * 2;
}
$zero = pack("C", 0);
$pps_sizeofname = pack("v", $length); // 0x40
$pps_type = pack("v", $type); // 0x42
$pps_prev = pack("V", -1); // 0x44
$pps_next = pack("V", -1); // 0x48
$pps_dir = pack("V", $dir); // 0x4c
$unknown1 = pack("V", 0);
$pps_ts1s = pack("V", 0); // 0x64
$pps_ts1d = pack("V", 0); // 0x68
$pps_ts2s = pack("V", 0); // 0x6c
$pps_ts2d = pack("V", 0); // 0x70
$pps_sb = pack("V", $start); // 0x74
$pps_size = pack("V", $size); // 0x78
fwrite($this->_filehandle, $rawname);
for ($i = 0; $i < (64 -$length); $i++) {
fwrite($this->_filehandle, $zero);
@ -398,8 +398,8 @@ class Spreadsheet_Excel_Writer_OLEwriter extends PEAR
{
$biffsize = $this->_biffsize;
if ($biffsize < 4096) {
$min_size = 4096;
} else {
$min_size = 4096;
} else {
$min_size = 512;
}
if ($biffsize % $min_size != 0) {

View File

@ -178,9 +178,9 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
$this->_ext_sheets = array();
$this->_references = array();
}
/**
* Initialize the ptg and function hashes.
* Initialize the ptg and function hashes.
*
* @access private
*/
@ -284,7 +284,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
'ptgRefErr3dA' => 0x7C,
'ptgAreaErr3d' => 0x7D
);
// Thanks to Michael Meeks and Gnumeric for the initial arg values.
//
// The following hash was generated by "function_locale.pl" in the distro.
@ -527,7 +527,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
'ROMAN' => array( 354, -1, 1, 0 )
);
}
/**
* Convert a token to the proper ptg value.
*
@ -576,7 +576,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
// TODO: use real error codes
return $this->raiseError("Unknown token $token");
}
/**
* Convert a number token to ptgInt or ptgNum
*
@ -595,12 +595,12 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
return pack("Cd", $this->ptg['ptgNum'], $num);
}
}
/**
* Convert a string token to ptgStr
*
* @access private
* @param string $string A string for conversion to its ptg value.
* @param string $string A string for conversion to its ptg value.
* @return mixed the converted token on success. PEAR_Error if the string
* is longer than 255 characters.
*/
@ -618,7 +618,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
return pack("CCC", $this->ptg['ptgStr'], strlen($string), $encoding).$string;
}
}
/**
* Convert a function to a ptgFunc or ptgFuncVarV depending on the number of
* args that it takes.
@ -632,7 +632,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
{
$args = $this->_functions[$token][1];
$volatile = $this->_functions[$token][3];
// Fixed number of args eg. TIME($i,$j,$k).
if ($args >= 0) {
return pack("Cv", $this->ptg['ptgFuncV'], $this->_functions[$token][0]);
@ -642,7 +642,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
return pack("CCv", $this->ptg['ptgFuncVarV'], $num_args, $this->_functions[$token][0]);
}
}
/**
* Convert an Excel range such as A1:D4 to a ptgRefV.
*
@ -652,18 +652,18 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
function _convertRange2d($range)
{
$class = 2; // as far as I know, this is magick.
// Split the range into 2 cell refs
if (preg_match("/^([A-Ia-i]?[A-Za-z])(\d+)\:([A-Ia-i]?[A-Za-z])(\d+)$/",$range)) {
list($cell1, $cell2) = split(':', $range);
} elseif (preg_match("/^([A-Ia-i]?[A-Za-z])(\d+)\.\.([A-Ia-i]?[A-Za-z])(\d+)$/",$range)) {
list($cell1, $cell2) = split('\.\.', $range);
} else {
// TODO: use real error codes
return $this->raiseError("Unknown range separator", 0, PEAR_ERROR_DIE);
}
// Convert the cell references
$cell_array1 = $this->_cellToPackedRowcol($cell1);
if (PEAR::isError($cell_array1)) {
@ -675,7 +675,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
return $cell_array2;
}
list($row2, $col2) = $cell_array2;
// The ptg value depends on the class of the ptg.
if ($class == 0) {
$ptgArea = pack("C", $this->ptg['ptgArea']);
@ -689,7 +689,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
}
return $ptgArea . $row1 . $row2 . $col1. $col2;
}
/**
* Convert an Excel 3d range such as "Sheet1!A1:D4" or "Sheet1:Sheet2!A1:D4" to
* a ptgArea3d.
@ -701,10 +701,10 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
function _convertRange3d($token)
{
$class = 2; // as far as I know, this is magick.
// Split the ref at the ! symbol
list($ext_ref, $range) = split('!', $token);
// Convert the external reference part (different for BIFF8)
if ($this->_BIFF_version == 0x0500) {
$ext_ref = $this->_packExtRef($ext_ref);
@ -720,7 +720,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
// Split the range into 2 cell refs
list($cell1, $cell2) = split(':', $range);
// Convert the cell references
if (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?(\d+)$/", $cell1)) {
$cell_array1 = $this->_cellToPackedRowcol($cell1);
@ -740,7 +740,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
}
list($row1, $col1, $row2, $col2) = $cells_array;
}
// The ptg value depends on the class of the ptg.
if ($class == 0) {
$ptgArea = pack("C", $this->ptg['ptgArea3d']);
@ -751,7 +751,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
} else {
return $this->raiseError("Unknown class $class", 0, PEAR_ERROR_DIE);
}
return $ptgArea . $ext_ref . $row1 . $row2 . $col1. $col2;
}
@ -765,14 +765,14 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
function _convertRef2d($cell)
{
$class = 2; // as far as I know, this is magick.
// Convert the cell reference
$cell_array = $this->_cellToPackedRowcol($cell);
if (PEAR::isError($cell_array)) {
return $cell_array;
}
list($row, $col) = $cell_array;
// The ptg value depends on the class of the ptg.
if ($class == 0) {
$ptgRef = pack("C", $this->ptg['ptgRef']);
@ -786,7 +786,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
}
return $ptgRef.$row.$col;
}
/**
* Convert an Excel 3d reference such as "Sheet1!A1" or "Sheet1:Sheet2!A1" to a
* ptgRef3d.
@ -798,10 +798,10 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
function _convertRef3d($cell)
{
$class = 2; // as far as I know, this is magick.
// Split the ref at the ! symbol
list($ext_ref, $cell) = split('!', $cell);
// Convert the external reference part (different for BIFF8)
if ($this->_BIFF_version == 0x0500) {
$ext_ref = $this->_packExtRef($ext_ref);
@ -817,7 +817,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
// Convert the cell reference part
list($row, $col) = $this->_cellToPackedRowcol($cell);
// The ptg value depends on the class of the ptg.
if ($class == 0) {
$ptgRef = pack("C", $this->ptg['ptgRef3d']);
@ -844,11 +844,11 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
{
$ext_ref = preg_replace("/^'/", '', $ext_ref); // Remove leading ' if any.
$ext_ref = preg_replace("/'$/", '', $ext_ref); // Remove trailing ' if any.
// Check if there is a sheet range eg., Sheet1:Sheet2.
if (preg_match("/:/", $ext_ref)) {
list($sheet_name1, $sheet_name2) = split(':', $ext_ref);
$sheet1 = $this->_getSheetIndex($sheet_name1);
if ($sheet1 == -1) {
return $this->raiseError("Unknown sheet name $sheet_name1 in formula");
@ -857,7 +857,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
if ($sheet2 == -1) {
return $this->raiseError("Unknown sheet name $sheet_name2 in formula");
}
// Reverse max and min sheet numbers if necessary
if ($sheet1 > $sheet2) {
list($sheet1, $sheet2) = array($sheet2, $sheet1);
@ -869,7 +869,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
}
$sheet2 = $sheet1;
}
// References are stored relative to 0xFFFF.
$offset = -1 - $sheet1;
@ -877,7 +877,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
}
/**
* Look up the REF index that corresponds to an external sheet name
* Look up the REF index that corresponds to an external sheet name
* (or range). If it doesn't exist yet add it to the workbook's references
* array. It assumes all sheet names given must exist.
*
@ -890,11 +890,11 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
{
$ext_ref = preg_replace("/^'/", '', $ext_ref); // Remove leading ' if any.
$ext_ref = preg_replace("/'$/", '', $ext_ref); // Remove trailing ' if any.
// Check if there is a sheet range eg., Sheet1:Sheet2.
if (preg_match("/:/", $ext_ref)) {
list($sheet_name1, $sheet_name2) = split(':', $ext_ref);
$sheet1 = $this->_getSheetIndex($sheet_name1);
if ($sheet1 == -1) {
return $this->raiseError("Unknown sheet name $sheet_name1 in formula");
@ -903,7 +903,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
if ($sheet2 == -1) {
return $this->raiseError("Unknown sheet name $sheet_name2 in formula");
}
// Reverse max and min sheet numbers if necessary
if ($sheet1 > $sheet2) {
list($sheet1, $sheet2) = array($sheet2, $sheet1);
@ -915,7 +915,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
}
$sheet2 = $sheet1;
}
// assume all references belong to this document
$supbook_index = 0x00;
$ref = pack('vvv', $supbook_index, $sheet1, $sheet2);
@ -938,7 +938,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
/**
* Look up the index that corresponds to an external sheet name. The hash of
* sheet names is updated by the addworksheet() method of the
* sheet names is updated by the addworksheet() method of the
* Spreadsheet_Excel_Writer_Workbook class.
*
* @access private
@ -986,7 +986,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
if ($row >= 16384) {
return $this->raiseError("Row in: $cell greater than 16384 ");
}
// Set the high bits to indicate if row or col are relative.
if ($this->_BIFF_version == 0x0500) {
$row |= $col_rel << 14;
@ -998,10 +998,10 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
$col = pack('v', $col);
}
$row = pack('v', $row);
return array($row, $col);
}
/**
* pack() row range into the required 3 or 4 byte format.
* Just using maximum col/rows, which is probably not the correct solution
@ -1029,7 +1029,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
if (($row1 >= 16384) or ($row2 >= 16384)) {
return $this->raiseError("Row in: $range greater than 16384 ");
}
// Set the high bits to indicate if rows are relative.
if ($this->_BIFF_version == 0x0500) {
$row1 |= $row1_rel << 14; // FIXME: probably a bug
@ -1044,7 +1044,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
}
$row1 = pack('v', $row1);
$row2 = pack('v', $row2);
return array($row1, $col1, $row2, $col2);
}
@ -1065,7 +1065,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
$col_ref = $match[2];
$row_rel = empty($match[3]) ? 1 : 0;
$row = $match[4];
// Convert base26 column string to a number.
$expn = strlen($col_ref) - 1;
$col = 0;
@ -1073,14 +1073,14 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
$col += (ord($col_ref{$i}) - ord('A') + 1) * pow(26, $expn);
$expn--;
}
// Convert 1-index to zero-index
$row--;
$col--;
return array($row, $col, $row_rel, $col_rel);
}
/**
* Advance to the next valid token.
*
@ -1123,7 +1123,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
}
//die("Lexical error ".$this->_current_char);
}
/**
* Checks if it's a valid token.
*
@ -1186,7 +1186,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
default:
// if it's a reference
if (preg_match('/^\$?[A-Ia-i]?[A-Za-z]\$?[0-9]+$/', $token) &&
!ereg("[0-9]", $this->_lookahead) &&
!ereg("[0-9]", $this->_lookahead) &&
($this->_lookahead != ':') && ($this->_lookahead != '.') &&
($this->_lookahead != '!'))
{
@ -1203,12 +1203,12 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
{
// If it's an external reference (Sheet1!A1 or Sheet1:Sheet2!A1)
return $token;
} elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+:(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/", $token) &&
} elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+:(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/", $token) &&
!ereg("[0-9]", $this->_lookahead))
{
// if it's a range (A1:A2)
return $token;
} elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+\.\.(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/", $token) &&
} elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+\.\.(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/", $token) &&
!ereg("[0-9]", $this->_lookahead))
{
// if it's a range (A1..A2)
@ -1223,7 +1223,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
{
// If it's an external range like 'Sheet1'!A1 or 'Sheet1:Sheet2'!A1:B2
return $token;
} elseif (is_numeric($token) &&
} elseif (is_numeric($token) &&
(!is_numeric($token.$this->_lookahead) || ($this->_lookahead == '')) &&
($this->_lookahead != '!') && ($this->_lookahead != ':'))
{
@ -1240,7 +1240,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
return '';
}
}
/**
* The parsing method. It parses a formula.
*
@ -1261,7 +1261,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
}
return true;
}
/**
* It parses a condition. It assumes the following rule:
* Cond -> Expr [(">" | "<") Expr]
@ -1348,7 +1348,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
if (PEAR::isError($result)) {
return $result;
}
while (($this->_current_token == SPREADSHEET_EXCEL_WRITER_ADD) ||
while (($this->_current_token == SPREADSHEET_EXCEL_WRITER_ADD) ||
($this->_current_token == SPREADSHEET_EXCEL_WRITER_SUB))
{
if ($this->_current_token == SPREADSHEET_EXCEL_WRITER_ADD) {
@ -1369,7 +1369,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
}
return $result;
}
/**
* This function just introduces a ptgParen element in the tree, so that Excel
* doesn't get confused when working with a parenthesized formula afterwards.
@ -1383,7 +1383,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
$result = $this->_createTree('ptgParen', $this->_expression(), '');
return $result;
}
/**
* It parses a term. It assumes the following rule:
* Term -> Fact [("*" | "/") Fact]
@ -1397,7 +1397,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
if (PEAR::isError($result)) {
return $result;
}
while (($this->_current_token == SPREADSHEET_EXCEL_WRITER_MUL) ||
while (($this->_current_token == SPREADSHEET_EXCEL_WRITER_MUL) ||
($this->_current_token == SPREADSHEET_EXCEL_WRITER_DIV))
{
if ($this->_current_token == SPREADSHEET_EXCEL_WRITER_MUL)
@ -1419,7 +1419,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
}
return $result;
}
/**
* It parses a factor. It assumes the following rule:
* Fact -> ( Expr )
@ -1457,7 +1457,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
$result = $this->_createTree($this->_current_token, '', '');
$this->_advance();
return $result;
} elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+:(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/", $this->_current_token) ||
} elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+:(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/", $this->_current_token) ||
preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+\.\.(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/", $this->_current_token))
{
// if it's a range
@ -1487,7 +1487,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
", lookahead: ".$this->_lookahead.
", current char: ".$this->_current_char);
}
/**
* It parses a function call. It assumes the following rule:
* Func -> ( Expr [,Expr]* )
@ -1530,12 +1530,12 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
if (($args >= 0) and ($args != $num_args)) {
return $this->raiseError("Incorrect number of arguments in function $function() ");
}
$result = $this->_createTree($function, $result, $num_args);
$this->_advance(); // eat the ")"
return $result;
}
/**
* Creates a tree. In fact an array which may have one or two arrays (sub-trees)
* as elements.
@ -1550,12 +1550,12 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
{
return array('value' => $value, 'left' => $left, 'right' => $right);
}
/**
* Builds a string containing the tree in reverse polish notation (What you
* Builds a string containing the tree in reverse polish notation (What you
* would use in a HP calculator stack).
* The following tree:
*
*
* +
* / \
* 2 3

View File

@ -170,7 +170,7 @@ class Spreadsheet_Excel_Writer_Validator
$options |= 0x80000;
}
$options |= $this->_operator << 20;
return $options;
}
@ -180,7 +180,7 @@ class Spreadsheet_Excel_Writer_Validator
$descr_prompt_len = strlen($this->_descr_prompt);
$title_error_len = strlen($this->_title_error);
$descr_error_len = strlen($this->_descr_error);
$formula1_size = strlen($this->_formula1);
$formula2_size = strlen($this->_formula2);
@ -209,7 +209,7 @@ class Spreadsheet_Excel_Writer_Validator
{
$this->_incell = $incell;
$this->_fixedList = true;
$source = implode("\x00", $source);
$this->_formula1 = pack("CCC", 0x17, strlen($source), 0x0c) . $source;
}

View File

@ -5,7 +5,7 @@
* The majority of this is _NOT_ my code. I simply ported it from the
* PERL Spreadsheet::WriteExcel module.
*
* The author of the Spreadsheet::WriteExcel module is John McNamara
* The author of the Spreadsheet::WriteExcel module is John McNamara
* <jmcnamara@cpan.org>
*
* I _DO_ maintain this code, and John McNamara has nothing to do with the
@ -181,7 +181,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
{
// It needs to call its parent's constructor explicitly
$this->Spreadsheet_Excel_Writer_BIFFwriter();
$this->_filename = $filename;
$this->_parser =& new Spreadsheet_Excel_Writer_Parser($this->_byte_order, $this->_BIFF_version);
$this->_1904 = 0;
@ -209,7 +209,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
$this->_setPaletteXl97();
$this->_tmp_dir = '';
}
/**
* Calls finalization methods.
* This method should always be the last one to be called on every workbook
@ -229,7 +229,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
$this->_fileclosed = 1;
return true;
}
/**
* An accessor for the _worksheets[] array
* Returns an array of the worksheet objects in a workbook
@ -243,7 +243,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
{
return $this->worksheets();
}
/**
* An accessor for the _worksheets[] array.
* Returns an array of the worksheet objects in a workbook
@ -255,7 +255,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
{
return $this->_worksheets;
}
/**
* Sets the BIFF version.
* This method exists just to access experimental functionality
@ -315,16 +315,16 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
{
$index = count($this->_worksheets);
$sheetname = $this->_sheetname;
if ($name == '') {
$name = $sheetname.($index+1);
$name = $sheetname.($index+1);
}
// Check that sheetname is <= 31 chars (Excel limit).
if (strlen($name) > 31) {
return $this->raiseError("Sheetname $name must be <= 31 chars");
}
// Check that the worksheet name doesn't already exist: a fatal Excel error.
$total_worksheets = count($this->_worksheets);
for ($i = 0; $i < $total_worksheets; $i++) {
@ -332,7 +332,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
return $this->raiseError("Worksheet '$name' already exists");
}
}
$worksheet = new Spreadsheet_Excel_Writer_Worksheet($this->_BIFF_version,
$name, $index,
$this->_activesheet, $this->_firstsheet,
@ -345,7 +345,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
$this->_parser->setExtSheet($name, $index); // Register worksheet name with parser
return $worksheet;
}
/**
* Add a new format to the Excel workbook.
* Also, pass any properties to the Format constructor.
@ -361,7 +361,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
$this->_formats[] = &$format;
return $format;
}
/**
* Create new validator.
*
@ -392,28 +392,28 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
/*if (defined $_[1] and $_[1] =~ /^#(\w\w)(\w\w)(\w\w)/ ) {
@_ = ($_[0], hex $1, hex $2, hex $3);
}*/
// Check that the colour index is the right range
if ($index < 8 or $index > 64) {
// TODO: assign real error codes
return $this->raiseError("Color index $index outside range: 8 <= index <= 64");
}
// Check that the colour components are in the right range
if (($red < 0 or $red > 255) ||
($green < 0 or $green > 255) ||
($blue < 0 or $blue > 255))
($blue < 0 or $blue > 255))
{
return $this->raiseError("Color component outside range: 0 <= color <= 255");
}
$index -= 8; // Adjust colour index (wingless dragonfly)
// Set the RGB value
$this->_palette[$index] = array($red, $green, $blue, 0);
return($index + 8);
}
/**
* Sets the colour palette to the Excel 97+ default.
*
@ -480,7 +480,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
array(0x33, 0x33, 0x33, 0x00), // 63
);
}
/**
* Assemble worksheets into a workbook and send the BIFF data to an OLE
* storage.
@ -494,7 +494,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
if ($this->_activesheet == 0) {
$this->_worksheets[0]->selected = 1;
}
// Calculate the number of selected worksheet tabs and call the finalization
// methods for each worksheet
$total_worksheets = count($this->_worksheets);
@ -504,7 +504,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
}
$this->_worksheets[$i]->close($this->_sheetnames);
}
// Add Workbook globals
$this->_storeBof(0x0005);
$this->_storeCodepage();
@ -525,19 +525,19 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
$this->_storeAllStyles();
$this->_storePalette();
$this->_calcSheetOffsets();
// Add BOUNDSHEET records
for ($i = 0; $i < $total_worksheets; $i++) {
$this->_storeBoundsheet($this->_worksheets[$i]->name,$this->_worksheets[$i]->offset);
}
if ($this->_country_code != -1) {
$this->_storeCountry();
}
if ($this->_BIFF_version == 0x0600) {
//$this->_storeSupbookInternal();
/* TODO: store external SUPBOOK records and XCT and CRN records
/* TODO: store external SUPBOOK records and XCT and CRN records
in case of external references for BIFF8 */
//$this->_storeExternsheetBiff8();
$this->_storeSharedStringsTable();
@ -545,7 +545,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
// End Workbook globals
$this->_storeEof();
// Store the workbook in an OLE container
$res = $this->_storeOLEFile();
if ($this->isError($res)) {
@ -553,7 +553,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
}
return true;
}
/**
* Sets the temp dir used for storing the OLE file
*
@ -603,7 +603,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
}
return true;
}
/**
* Calculate offsets for Worksheet BOF records.
*
@ -630,7 +630,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
//$offset += 8; // FIXME: calculate real value when storing the records
}
$total_worksheets = count($this->_worksheets);
// add the length of the BOUNDSHEET records
// add the length of the BOUNDSHEET records
for ($i = 0; $i < $total_worksheets; $i++) {
$offset += $boundsheet_length + strlen($this->_worksheets[$i]->name);
}
@ -642,7 +642,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
}
$this->_biffsize = $offset;
}
/**
* Store the Excel FONT records.
*
@ -653,20 +653,20 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
// tmp_format is added by the constructor. We use this to write the default XF's
$format = $this->_tmp_format;
$font = $format->getFont();
// Note: Fonts are 0-indexed. According to the SDK there is no index 4,
// so the following fonts are 0, 1, 2, 3, 5
//
for ($i = 1; $i <= 5; $i++){
$this->_append($font);
}
// Iterate through the XF objects and write a FONT record if it isn't the
// same as the default FONT and if it hasn't already been used.
//
$fonts = array();
$index = 6; // The first user defined FONT
$key = $format->getFontKey(); // The default font from _tmp_format
$fonts[$key] = 0; // Index of the default font
@ -686,7 +686,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
}
}
}
/**
* Store user defined numerical formats i.e. FORMAT records
*
@ -698,13 +698,13 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
$hash_num_formats = array();
$num_formats = array();
$index = 164;
// Iterate through the XF objects and write a FORMAT record if it isn't a
// built-in format type and if the FORMAT string hasn't already been used.
$total_formats = count($this->_formats);
for ($i = 0; $i < $total_formats; $i++) {
$num_format = $this->_formats[$i]->_num_format;
// Check if $num_format is an index to a built-in format.
// Also check for a string of zeros, which is a valid format string
// but would evaluate to zero.
@ -714,7 +714,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
continue;
}
}
if (isset($hash_num_formats[$num_format])) {
// FORMAT has already been used
$this->_formats[$i]->_num_format = $hash_num_formats[$num_format];
@ -726,7 +726,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
$index++;
}
}
// Write the new FORMAT records starting from 0xA4
$index = 164;
foreach ($num_formats as $num_format) {
@ -734,7 +734,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
$index++;
}
}
/**
* Write all XF records.
*
@ -750,10 +750,10 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
$xf = $format->getXf('style'); // Style XF
$this->_append($xf);
}
$xf = $format->getXf('cell'); // Cell XF
$this->_append($xf);
// User defined XFs
$total_formats = count($this->_formats);
for ($i = 0; $i < $total_formats; $i++) {
@ -761,17 +761,17 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
$this->_append($xf);
}
}
/**
* Write all STYLE records.
*
* @access private
* @access private
*/
function _storeAllStyles()
{
$this->_storeStyle();
}
/**
* Write the EXTERNCOUNT and EXTERNSHEET records. These are used as indexes for
* the NAME records.
@ -782,13 +782,13 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
{
// Create EXTERNCOUNT with number of worksheets
$this->_storeExterncount(count($this->_worksheets));
// Create EXTERNSHEET for each worksheet
foreach ($this->_sheetnames as $sheetname) {
$this->_storeExternsheet($sheetname);
}
}
/**
* Write the NAME record to define the print area and the repeat rows and cols.
*
@ -811,7 +811,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
);
}
}
// Create the print title NAME records
$total_worksheets = count($this->_worksheets);
for ($i = 0; $i < $total_worksheets; $i++) {
@ -819,7 +819,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
$rowmax = $this->_worksheets[$i]->title_rowmax;
$colmin = $this->_worksheets[$i]->title_colmin;
$colmax = $this->_worksheets[$i]->title_colmax;
// Determine if row + col, row, col or nothing has been defined
// and write the appropriate record
//
@ -859,16 +859,16 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
}
}
}
/******************************************************************************
*
* BIFF RECORDS
*
*/
/**
* Stores the CODEPAGE biff record.
*
@ -879,10 +879,10 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
$record = 0x0042; // Record identifier
$length = 0x0002; // Number of bytes to follow
$cv = $this->_codepage; // The code page
$header = pack('vv', $record, $length);
$data = pack('v', $cv);
$this->_append($header.$data);
}
@ -895,19 +895,19 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
{
$record = 0x003D; // Record identifier
$length = 0x0012; // Number of bytes to follow
$xWn = 0x0000; // Horizontal position of window
$yWn = 0x0000; // Vertical position of window
$dxWn = 0x25BC; // Width of window
$dyWn = 0x1572; // Height of window
$grbit = 0x0038; // Option flags
$ctabsel = $this->_selected; // Number of workbook tabs selected
$wTabRatio = 0x0258; // Tab to scrollbar ratio
$itabFirst = $this->_firstsheet; // 1st displayed worksheet
$itabCur = $this->_activesheet; // Active worksheet
$header = pack("vv", $record, $length);
$data = pack("vvvvvvvvv", $xWn, $yWn, $dxWn, $dyWn,
$grbit,
@ -915,7 +915,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
$ctabsel, $wTabRatio);
$this->_append($header.$data);
}
/**
* Writes Excel BIFF BOUNDSHEET record.
* FIXME: inconsistent with BIFF documentation
@ -932,10 +932,10 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
} else {
$length = 0x07 + strlen($sheetname); // Number of bytes to follow
}
$grbit = 0x0000; // Visibility and sheet type
$cch = strlen($sheetname); // Length of sheet name
$header = pack("vv", $record, $length);
if ($this->_BIFF_version == 0x0600) {
$data = pack("Vvv", $offset, $grbit, $cch);
@ -944,7 +944,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
}
$this->_append($header.$data.$sheetname);
}
/**
* Write Internal SUPBOOK record
*
@ -954,7 +954,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
{
$record = 0x01AE; // Record identifier
$length = 0x0004; // Bytes to follow
$header = pack("vv", $record, $length);
$data = pack("vv", count($this->_worksheets), 0x0104);
$this->_append($header.$data);
@ -962,7 +962,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
/**
* Writes the Excel BIFF EXTERNSHEET record. These references are used by
* formulas.
* formulas.
*
* @param string $sheetname Worksheet name
* @access private
@ -991,17 +991,17 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
{
$record = 0x0293; // Record identifier
$length = 0x0004; // Bytes to follow
$ixfe = 0x8000; // Index to style XF
$BuiltIn = 0x00; // Built-in style
$iLevel = 0xff; // Outline style level
$header = pack("vv", $record, $length);
$data = pack("vCC", $ixfe, $BuiltIn, $iLevel);
$this->_append($header.$data);
}
/**
* Writes Excel FORMAT record for non "built-in" numerical formats.
*
@ -1021,7 +1021,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
}
$cch = strlen($format); // Length of format string
$header = pack("vv", $record, $length);
if ($this->_BIFF_version == 0x0600) {
$data = pack("vvC", $ifmt, $cch, $encoding);
@ -1030,7 +1030,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
}
$this->_append($header.$data.$format);
}
/**
* Write DATEMODE record to indicate the date system in use (1904 or 1900).
*
@ -1040,15 +1040,15 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
{
$record = 0x0022; // Record identifier
$length = 0x0002; // Bytes to follow
$f1904 = $this->_1904; // Flag for 1904 date system
$header = pack("vv", $record, $length);
$data = pack("v", $f1904);
$this->_append($header.$data);
}
/**
* Write BIFF record EXTERNCOUNT to indicate the number of external sheet
* references in the workbook.
@ -1066,13 +1066,13 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
{
$record = 0x0016; // Record identifier
$length = 0x0002; // Number of bytes to follow
$header = pack("vv", $record, $length);
$data = pack("v", $cxals);
$this->_append($header.$data);
}
/**
* Writes the Excel BIFF EXTERNSHEET record. These references are used by
* formulas. NAME record is required to define the print area and the repeat
@ -1087,16 +1087,16 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
{
$record = 0x0017; // Record identifier
$length = 0x02 + strlen($sheetname); // Number of bytes to follow
$cch = strlen($sheetname); // Length of sheet name
$rgch = 0x03; // Filename encoding
$header = pack("vv", $record, $length);
$data = pack("CC", $cch, $rgch);
$this->_append($header.$data.$sheetname);
}
/**
* Store the NAME record in the short format that is used for storing the print
* area, repeat rows only and repeat columns only.
@ -1113,7 +1113,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
{
$record = 0x0018; // Record identifier
$length = 0x0024; // Number of bytes to follow
$grbit = 0x0020; // Option flags
$chKey = 0x00; // Keyboard shortcut
$cch = 0x01; // Length of text name
@ -1125,14 +1125,14 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
$cchHelptopic = 0x00; // Length of help topic text
$cchStatustext = 0x00; // Length of status bar text
$rgch = $type; // Built-in name type
$unknown03 = 0x3b;
$unknown04 = 0xffff-$index;
$unknown05 = 0x0000;
$unknown06 = 0x0000;
$unknown07 = 0x1087;
$unknown08 = 0x8005;
$header = pack("vv", $record, $length);
$data = pack("v", $grbit);
$data .= pack("C", $chKey);
@ -1159,8 +1159,8 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
$data .= pack("C", $colmax);
$this->_append($header.$data);
}
/**
* Store the NAME record in the long format that is used for storing the repeat
* rows and columns when both are specified. This shares a lot of code with
@ -1190,7 +1190,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
$cchHelptopic = 0x00; // Length of help topic text
$cchStatustext = 0x00; // Length of status bar text
$rgch = $type; // Built-in name type
$unknown01 = 0x29;
$unknown02 = 0x002b;
$unknown03 = 0x3b;
@ -1199,7 +1199,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
$unknown06 = 0x0000;
$unknown07 = 0x1087;
$unknown08 = 0x8008;
$header = pack("vv", $record, $length);
$data = pack("v", $grbit);
$data .= pack("C", $chKey);
@ -1244,7 +1244,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
$data .= pack("C", 0x10);
$this->_append($header.$data);
}
/**
* Stores the COUNTRY record for localization
*
@ -1260,7 +1260,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
$data = pack('vv', $this->_country_code, $this->_country_code);
$this->_append($header.$data);
}
/**
* Stores the PALETTE biff record.
*
@ -1269,19 +1269,19 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
function _storePalette()
{
$aref = $this->_palette;
$record = 0x0092; // Record identifier
$length = 2 + 4 * count($aref); // Number of bytes to follow
$ccv = count($aref); // Number of RGB values to follow
$data = ''; // The RGB data
// Pack the RGB data
foreach($aref as $color) {
foreach($color as $byte) {
$data .= pack("C",$byte);
}
}
$header = pack("vvv", $record, $length, $ccv);
$this->_append($header.$data);
}
@ -1313,43 +1313,43 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
foreach (array_keys($this->_str_table) as $string) {
$string_length = strlen($string);
// Block length is the total length of the strings that will be
// written out in a single SST or CONTINUE block.
$block_length += $string_length;
// We can write the string if it doesn't cross a CONTINUE boundary
if ($block_length < $continue_limit) {
$written += $string_length;
continue;
}
// Deal with the cases where the next string to be written will exceed
// the CONTINUE boundary. If the string is very long it may need to be
// written in more than one CONTINUE record.
while ($block_length >= $continue_limit) {
// We need to avoid the case where a string is continued in the first
// n bytes that contain the string header information.
$header_length = 3; // Min string + header size -1
$space_remaining = $continue_limit - $written - $continue;
/* TODO: Unicode data should only be split on char (2 byte)
boundaries. Therefore, in some cases we need to reduce the
amount of available
*/
if ($space_remaining > $header_length) {
// Write as much as possible of the string in the current block
$written += $space_remaining;
// Reduce the current block length by the amount written
$block_length -= $continue_limit - $continue;
// Store the max size for this block
$this->_block_sizes[] = $continue_limit;
// If the current string was split then the next CONTINUE block
// should have the string continue flag (grbit) set unless the
// split string fits exactly into the remaining space.
@ -1361,13 +1361,13 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
} else {
// Store the max size for this block
$this->_block_sizes[] = $written + $continue;
// Not enough space to start the string in the current block
$block_length -= $continue_limit - $space_remaining - $continue;
$continue = 0;
}
// If the string (or substr) is small enough we can write it in the
// new CONTINUE block. Else, go through the loop again to write it in
// one or more CONTINUE blocks
@ -1383,8 +1383,8 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
if ($written + $continue) {
$this->_block_sizes[] = $written + $continue;
}
/* Calculate the total length of the SST and associated CONTINUEs (if any).
The SST record will have a length even if it contains no strings.
This length is required to set the offsets in the BOUNDSHEET records since
@ -1436,47 +1436,47 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
$string_length = strlen($string);
$encoding = 0; // assume there are no Unicode strings
$split_string = 0;
// Block length is the total length of the strings that will be
// written out in a single SST or CONTINUE block.
//
$block_length += $string_length;
// We can write the string if it doesn't cross a CONTINUE boundary
if ($block_length < $continue_limit) {
$this->_append($string);
$written += $string_length;
continue;
}
// Deal with the cases where the next string to be written will exceed
// the CONTINUE boundary. If the string is very long it may need to be
// written in more than one CONTINUE record.
//
//
while ($block_length >= $continue_limit) {
// We need to avoid the case where a string is continued in the first
// n bytes that contain the string header information.
//
$header_length = 3; // Min string + header size -1
$space_remaining = $continue_limit - $written - $continue;
// Unicode data should only be split on char (2 byte) boundaries.
// Therefore, in some cases we need to reduce the amount of available
if ($space_remaining > $header_length) {
// Write as much as possible of the string in the current block
$tmp = substr($string, 0, $space_remaining);
$this->_append($tmp);
// The remainder will be written in the next block(s)
$string = substr($string, $space_remaining);
// Reduce the current block length by the amount written
$block_length -= $continue_limit - $continue;
// If the current string was split then the next CONTINUE block
// should have the string continue flag (grbit) set unless the
// split string fits exactly into the remaining space.
@ -1491,7 +1491,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
$block_length -= $continue_limit - $space_remaining - $continue;
$continue = 0;
}
// Write the CONTINUE block header
if (!empty($this->_block_sizes)) {
$record = 0x003C;
@ -1502,7 +1502,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
}
$this->_append($header);
}
// If the string (or substr) is small enough we can write it in the
// new CONTINUE block. Else, go through the loop again to write it in
// one or more CONTINUE blocks

File diff suppressed because it is too large Load Diff