Cosmetics and small speed up changes.

git-svn-id: https://svn.php.net/repository/pear/packages/Spreadsheet_Excel_Writer/trunk@197043 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Helgi Þormar Þorbjörnsson 2005-09-27 08:55:23 +00:00
parent 593af9f3bb
commit af802845ac
8 changed files with 164 additions and 146 deletions

View File

@ -221,7 +221,8 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
$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. // Retrieve chunks of 2080/8224 bytes +4 for the header.
for ($i = $limit; $i < strlen($data) - $limit; $i += $limit) { $data_length = strlen($data);
for ($i = $limit; $i < ($data_length - $limit); $i += $limit) {
$tmp .= $header; $tmp .= $header;
$tmp .= substr($data, $i, $limit); $tmp .= substr($data, $i, $limit);
} }

View File

@ -315,7 +315,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
function getXf($style) function getXf($style)
{ {
// Set the type of the XF record and some of the attributes. // Set the type of the XF record and some of the attributes.
if ($style == "style") { if ($style == 'style') {
$style = 0xFFF5; $style = 0xFFF5;
} else { } else {
$style = $this->_locked; $style = $this->_locked;
@ -507,7 +507,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
$key .= "$this->_font_strikeout$this->_bold$this->_font_outline"; $key .= "$this->_font_strikeout$this->_bold$this->_font_outline";
$key .= "$this->_font_family$this->_font_charset"; $key .= "$this->_font_family$this->_font_charset";
$key .= "$this->_font_shadow$this->_color$this->_italic"; $key .= "$this->_font_shadow$this->_color$this->_italic";
$key = str_replace(" ","_",$key); $key = str_replace(' ', '_', $key);
return ($key); return ($key);
} }

View File

@ -107,8 +107,8 @@ class Spreadsheet_Excel_Writer_OLEwriter extends PEAR
function Spreadsheet_Excel_Writer_OLEwriter($OLEfilename) function Spreadsheet_Excel_Writer_OLEwriter($OLEfilename)
{ {
$this->_OLEfilename = $OLEfilename; $this->_OLEfilename = $OLEfilename;
$this->_filehandle = ""; $this->_filehandle = '';
$this->_tmp_filename = ""; $this->_tmp_filename = '';
$this->_fileclosed = 0; $this->_fileclosed = 0;
$this->_biff_only = 0; $this->_biff_only = 0;
//$this->_size_allowed = 0; //$this->_size_allowed = 0;
@ -302,11 +302,13 @@ class Spreadsheet_Excel_Writer_OLEwriter extends PEAR
for ($i = 1; $i < $num_blocks; $i++) { for ($i = 1; $i < $num_blocks; $i++) {
fwrite($this->_filehandle, pack("V",$i)); fwrite($this->_filehandle, pack("V",$i));
} }
fwrite($this->_filehandle, $end_of_chain); fwrite($this->_filehandle, $end_of_chain);
fwrite($this->_filehandle, $end_of_chain); fwrite($this->_filehandle, $end_of_chain);
for ($i = 0; $i < $num_lists; $i++) { for ($i = 0; $i < $num_lists; $i++) {
fwrite($this->_filehandle, $marker); fwrite($this->_filehandle, $marker);
} }
for ($i = $used_blocks; $i <= $total_blocks; $i++) { for ($i = $used_blocks; $i <= $total_blocks; $i++) {
fwrite($this->_filehandle, $unused); fwrite($this->_filehandle, $unused);
} }
@ -344,7 +346,8 @@ class Spreadsheet_Excel_Writer_OLEwriter extends PEAR
if ($name != '') { if ($name != '') {
$name = $name . "\0"; $name = $name . "\0";
for ($i = 0; $i < strlen($name); $i++) { $name_length = strlen($name);
for ($i = 0; $i < $name_length; $i++) {
// Simulate a Unicode string // Simulate a Unicode string
$rawname .= pack("H*",dechex(ord($name{$i}))).pack("C",0); $rawname .= pack("H*",dechex(ord($name{$i}))).pack("C",0);
} }

View File

@ -170,7 +170,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
$this->_current_char = 0; $this->_current_char = 0;
$this->_BIFF_version = $biff_version; $this->_BIFF_version = $biff_version;
$this->_current_token = ''; // The token we are working on. $this->_current_token = ''; // The token we are working on.
$this->_formula = ""; // The formula to parse. $this->_formula = ''; // The formula to parse.
$this->_lookahead = ''; // The character ahead of the current char. $this->_lookahead = ''; // The character ahead of the current char.
$this->_parse_tree = ''; // The parse tree to be generated. $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 function's ptg's
@ -611,6 +611,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
if (strlen($string) > 255) { if (strlen($string) > 255) {
return $this->raiseError("String is too long"); return $this->raiseError("String is too long");
} }
if ($this->_BIFF_version == 0x0500) { if ($this->_BIFF_version == 0x0500) {
return pack("CC", $this->ptg['ptgStr'], strlen($string)).$string; return pack("CC", $this->ptg['ptgStr'], strlen($string)).$string;
} elseif ($this->_BIFF_version == 0x0600) { } elseif ($this->_BIFF_version == 0x0600) {
@ -1069,7 +1070,8 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
// Convert base26 column string to a number. // Convert base26 column string to a number.
$expn = strlen($col_ref) - 1; $expn = strlen($col_ref) - 1;
$col = 0; $col = 0;
for ($i = 0; $i < strlen($col_ref); $i++) { $col_ref_length = strlen($col_ref);
for ($i = 0; $i < $col_ref_length; $i++) {
$col += (ord($col_ref{$i}) - ord('A') + 1) * pow(26, $expn); $col += (ord($col_ref{$i}) - ord('A') + 1) * pow(26, $expn);
$expn--; $expn--;
} }
@ -1089,23 +1091,27 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
function _advance() function _advance()
{ {
$i = $this->_current_char; $i = $this->_current_char;
$formula_length = strlen($this->_formula);
// eat up white spaces // eat up white spaces
if ($i < strlen($this->_formula)) { if ($i < $formula_length) {
while ($this->_formula{$i} == " ") { while ($this->_formula{$i} == " ") {
$i++; $i++;
} }
if ($i < strlen($this->_formula) - 1) {
if ($i < ($formula_length - 1)) {
$this->_lookahead = $this->_formula{$i+1}; $this->_lookahead = $this->_formula{$i+1};
} }
$token = ""; $token = '';
} }
while ($i < strlen($this->_formula)) {
while ($i < $formula_length) {
$token .= $this->_formula{$i}; $token .= $this->_formula{$i};
if ($i < strlen($this->_formula) - 1) { if ($i < ($formula_length - 1)) {
$this->_lookahead = $this->_formula{$i+1}; $this->_lookahead = $this->_formula{$i+1};
} else { } else {
$this->_lookahead = ''; $this->_lookahead = '';
} }
if ($this->_match($token) != '') { if ($this->_match($token) != '') {
//if ($i < strlen($this->_formula) - 1) { //if ($i < strlen($this->_formula) - 1) {
// $this->_lookahead = $this->_formula{$i+1}; // $this->_lookahead = $this->_formula{$i+1};
@ -1114,7 +1120,8 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
$this->_current_token = $token; $this->_current_token = $token;
return 1; return 1;
} }
if ($i < strlen($this->_formula) - 2) {
if ($i < ($formula_length - 2)) {
$this->_lookahead = $this->_formula{$i+2}; $this->_lookahead = $this->_formula{$i+2};
} else { // if we run out of characters _lookahead becomes empty } else { // if we run out of characters _lookahead becomes empty
$this->_lookahead = ''; $this->_lookahead = '';

View File

@ -82,8 +82,8 @@ class Spreadsheet_Excel_Writer_Validator
$this->_title_error = "\x00"; $this->_title_error = "\x00";
$this->_descr_error = "\x00"; $this->_descr_error = "\x00";
$this->_operator = 0x00; // default is equal $this->_operator = 0x00; // default is equal
$this->_formula1 = ""; $this->_formula1 = '';
$this->_formula2 = ""; $this->_formula2 = '';
} }
function setPrompt($promptTitle = "\x00", $promptDescription = "\x00", $showPrompt = true) function setPrompt($promptTitle = "\x00", $promptDescription = "\x00", $showPrompt = true)

View File

@ -191,7 +191,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
$this->_xf_index = 16; // 15 style XF's and 1 cell XF. $this->_xf_index = 16; // 15 style XF's and 1 cell XF.
$this->_fileclosed = 0; $this->_fileclosed = 0;
$this->_biffsize = 0; $this->_biffsize = 0;
$this->_sheetname = "Sheet"; $this->_sheetname = 'Sheet';
$this->_tmp_format =& new Spreadsheet_Excel_Writer_Format($this->_BIFF_version); $this->_tmp_format =& new Spreadsheet_Excel_Writer_Format($this->_BIFF_version);
$this->_worksheets = array(); $this->_worksheets = array();
$this->_sheetnames = array(); $this->_sheetnames = array();
@ -276,11 +276,13 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
$this->_tmp_format->_BIFF_version = $version; $this->_tmp_format->_BIFF_version = $version;
$this->_url_format->_BIFF_version = $version; $this->_url_format->_BIFF_version = $version;
$this->_parser->_BIFF_version = $version; $this->_parser->_BIFF_version = $version;
$total_worksheets = count($this->_worksheets); $total_worksheets = count($this->_worksheets);
// change version for all worksheets too // change version for all worksheets too
for ($i = 0; $i < $total_worksheets; $i++) { for ($i = 0; $i < $total_worksheets; $i++) {
$this->_worksheets[$i]->_BIFF_version = $version; $this->_worksheets[$i]->_BIFF_version = $version;
} }
$total_formats = count($this->_formats); $total_formats = count($this->_formats);
// change version for all formats too // change version for all formats too
for ($i = 0; $i < $total_formats; $i++) { for ($i = 0; $i < $total_formats; $i++) {
@ -328,7 +330,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
// Check that the worksheet name doesn't already exist: a fatal Excel error. // Check that the worksheet name doesn't already exist: a fatal Excel error.
$total_worksheets = count($this->_worksheets); $total_worksheets = count($this->_worksheets);
for ($i = 0; $i < $total_worksheets; $i++) { for ($i = 0; $i < $total_worksheets; $i++) {
if ($name == $this->_worksheets[$i]->getName()) { if ($this->_worksheets[$i]->getName() == $name) {
return $this->raiseError("Worksheet '$name' already exists"); return $this->raiseError("Worksheet '$name' already exists");
} }
} }
@ -587,16 +589,19 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
return $this->raiseError("OLE Error: ".$res->getMessage()); return $this->raiseError("OLE Error: ".$res->getMessage());
} }
$OLE->append($this->_data); $OLE->append($this->_data);
$total_worksheets = count($this->_worksheets); $total_worksheets = count($this->_worksheets);
for ($i = 0; $i < $total_worksheets; $i++) { for ($i = 0; $i < $total_worksheets; $i++) {
while ($tmp = $this->_worksheets[$i]->getData()) { while ($tmp = $this->_worksheets[$i]->getData()) {
$OLE->append($tmp); $OLE->append($tmp);
} }
} }
$root = new OLE_PPS_Root(time(), time(), array($OLE)); $root = new OLE_PPS_Root(time(), time(), array($OLE));
if ($this->_tmp_dir != '') { if ($this->_tmp_dir != '') {
$root->setTempDir($this->_tmp_dir); $root->setTempDir($this->_tmp_dir);
} }
$res = $root->save($this->_filename); $res = $root->save($this->_filename);
if ($this->isError($res)) { if ($this->isError($res)) {
return $this->raiseError("OLE Error: ".$res->getMessage()); return $this->raiseError("OLE Error: ".$res->getMessage());

View File

@ -383,7 +383,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$this->_parser = &$parser; $this->_parser = &$parser;
//$this->ext_sheets = array(); //$this->ext_sheets = array();
$this->_filehandle = ""; $this->_filehandle = '';
$this->_using_tmpfile = true; $this->_using_tmpfile = true;
//$this->fileclosed = 0; //$this->fileclosed = 0;
//$this->offset = 0; //$this->offset = 0;
@ -414,14 +414,14 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$this->_margin_top = 1.00; $this->_margin_top = 1.00;
$this->_margin_bottom = 1.00; $this->_margin_bottom = 1.00;
$this->title_rowmin = NULL; $this->title_rowmin = null;
$this->title_rowmax = NULL; $this->title_rowmax = null;
$this->title_colmin = NULL; $this->title_colmin = null;
$this->title_colmax = NULL; $this->title_colmax = null;
$this->print_rowmin = NULL; $this->print_rowmin = null;
$this->print_rowmax = NULL; $this->print_rowmax = null;
$this->print_colmin = NULL; $this->print_colmin = null;
$this->print_colmax = NULL; $this->print_colmax = null;
$this->_print_gridlines = 1; $this->_print_gridlines = 1;
$this->_screen_gridlines = 1; $this->_screen_gridlines = 1;
@ -435,7 +435,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$this->_vbreaks = array(); $this->_vbreaks = array();
$this->_protect = 0; $this->_protect = 0;
$this->_password = NULL; $this->_password = null;
$this->col_sizes = array(); $this->col_sizes = array();
$this->_row_sizes = array(); $this->_row_sizes = array();
@ -568,7 +568,8 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
// Prepend the COLINFO records if they exist // Prepend the COLINFO records if they exist
if (!empty($this->_colinfo)) { if (!empty($this->_colinfo)) {
for ($i = 0; $i < count($this->_colinfo); $i++) { $colcount = count($this->_colinfo);
for ($i = 0; $i < $colcount; $i++) {
$this->_storeColinfo($this->_colinfo[$i]); $this->_storeColinfo($this->_colinfo[$i]);
} }
$this->_storeDefcol(); $this->_storeDefcol();
@ -956,7 +957,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
* @param integer $first_row First row to repeat * @param integer $first_row First row to repeat
* @param integer $last_row Last row to repeat. Optional. * @param integer $last_row Last row to repeat. Optional.
*/ */
function repeatRows($first_row, $last_row = NULL) function repeatRows($first_row, $last_row = null)
{ {
$this->title_rowmin = $first_row; $this->title_rowmin = $first_row;
if (isset($last_row)) { //Second row is optional if (isset($last_row)) { //Second row is optional
@ -973,7 +974,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
* @param integer $first_col First column to repeat * @param integer $first_col First column to repeat
* @param integer $last_col Last column to repeat. Optional. * @param integer $last_col Last column to repeat. Optional.
*/ */
function repeatColumns($first_col, $last_col = NULL) function repeatColumns($first_col, $last_col = null)
{ {
$this->title_colmin = $first_col; $this->title_colmin = $first_col;
if (isset($last_col)) { // Second col is optional if (isset($last_col)) { // Second col is optional
@ -1992,8 +1993,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$sheet_len = pack("V", strlen($sheet) + 0x01); $sheet_len = pack("V", strlen($sheet) + 0x01);
$sheet = join("\0", split('', $sheet)); $sheet = join("\0", split('', $sheet));
$sheet .= "\0\0\0"; $sheet .= "\0\0\0";
} } else {
else {
$sheet_len = ''; $sheet_len = '';
$sheet = ''; $sheet = '';
} }
@ -2055,7 +2055,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
* @access public * @access public
* @param integer $row The row to set * @param integer $row The row to set
* @param integer $height Height we are giving to the row. * @param integer $height Height we are giving to the row.
* Use NULL to set XF without setting height * Use null to set XF without setting height
* @param mixed $format XF format we are giving to the row * @param mixed $format XF format we are giving to the row
* @param bool $hidden The optional hidden attribute * @param bool $hidden The optional hidden attribute
* @param integer $level The optional outline level for row, in range [0,7] * @param integer $level The optional outline level for row, in range [0,7]
@ -2075,8 +2075,8 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
// set _row_sizes so _sizeRow() can use it // set _row_sizes so _sizeRow() can use it
$this->_row_sizes[$row] = $height; $this->_row_sizes[$row] = $height;
// Use setRow($row, NULL, $XF) to set XF format without setting height // Use setRow($row, null, $XF) to set XF format without setting height
if ($height != NULL) { if ($height != null) {
$miyRw = $height * 20; // row height $miyRw = $height * 20; // row height
} else { } else {
$miyRw = 0xff; // default row height is 256 $miyRw = 0xff; // default row height is 256
@ -2414,7 +2414,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
if (count($panes) > 4) { // if Active pane was received if (count($panes) > 4) { // if Active pane was received
$pnnAct = $panes[4]; $pnnAct = $panes[4];
} else { } else {
$pnnAct = NULL; $pnnAct = null;
} }
$record = 0x0041; // Record identifier $record = 0x0041; // Record identifier
$length = 0x000A; // Number of bytes to follow $length = 0x000A; // Number of bytes to follow
@ -2550,6 +2550,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
} else { } else {
$length = 1 + $cch; // Bytes to follow $length = 1 + $cch; // Bytes to follow
} }
$header = pack("vv", $record, $length); $header = pack("vv", $record, $length);
if ($this->_BIFF_version == 0x0600) { if ($this->_BIFF_version == 0x0600) {
$data = pack("vC", $cch, $encoding); $data = pack("vC", $cch, $encoding);
@ -2577,6 +2578,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
} else { } else {
$length = 1 + $cch; $length = 1 + $cch;
} }
$header = pack("vv", $record, $length); $header = pack("vv", $record, $length);
if ($this->_BIFF_version == 0x0600) { if ($this->_BIFF_version == 0x0600) {
$data = pack("vC", $cch, $encoding); $data = pack("vC", $cch, $encoding);
@ -2813,7 +2815,8 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
// Calculate the maximum column outline level. The equivalent calculation // Calculate the maximum column outline level. The equivalent calculation
// for the row outline level is carried out in setRow(). // for the row outline level is carried out in setRow().
for ($i = 0; $i < count($this->_colinfo); $i++) { $colcount = count($this->_colinfo);
for ($i = 0; $i < $colcount; $i++) {
// Skip cols without outline level info. // Skip cols without outline level info.
if (count($col_level) >= 6) { if (count($col_level) >= 6) {
$col_level = max($this->_colinfo[$i][5], $col_level); $col_level = max($this->_colinfo[$i][5], $col_level);
@ -3160,8 +3163,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$this->_storeObjPicture($col_start, $x1, $this->_storeObjPicture($col_start, $x1,
$row_start, $y1, $row_start, $y1,
$col_end, $x2, $col_end, $x2,
$row_end, $y2 $row_end, $y2);
);
} }
/** /**