Performance improvements by removing tests against BIFF version... especially as we only save as BIFF8 now, BIFF5 having been discarded some releases ago

git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@74466 2327b42d-5241-43d6-9e2a-de5ac946f064
This commit is contained in:
Mark Baker 2011-05-26 20:17:48 +00:00
parent 48b2fb8e99
commit c792f053b5
7 changed files with 187 additions and 462 deletions

View File

@ -107,7 +107,7 @@ class PHPExcel_Writer_Excel5 implements PHPExcel_Writer_IWriter
public function __construct(PHPExcel $phpExcel) { public function __construct(PHPExcel $phpExcel) {
$this->_phpExcel = $phpExcel; $this->_phpExcel = $phpExcel;
$this->_parser = new PHPExcel_Writer_Excel5_Parser($this->_BIFF_version); $this->_parser = new PHPExcel_Writer_Excel5_Parser();
} }
/** /**
@ -130,18 +130,18 @@ class PHPExcel_Writer_Excel5 implements PHPExcel_Writer_IWriter
$this->_colors = array(); $this->_colors = array();
// Initialise workbook writer // Initialise workbook writer
$this->_writerWorkbook = new PHPExcel_Writer_Excel5_Workbook($this->_phpExcel, $this->_BIFF_version, $this->_writerWorkbook = new PHPExcel_Writer_Excel5_Workbook($this->_phpExcel,
$this->_str_total, $this->_str_unique, $this->_str_table, $this->_colors, $this->_parser); $this->_str_total, $this->_str_unique, $this->_str_table,
$this->_colors, $this->_parser);
// Initialise worksheet writers // Initialise worksheet writers
$countSheets = $this->_phpExcel->getSheetCount(); $countSheets = $this->_phpExcel->getSheetCount();
for ($i = 0; $i < $countSheets; ++$i) { for ($i = 0; $i < $countSheets; ++$i) {
$this->_writerWorksheets[$i] = new PHPExcel_Writer_Excel5_Worksheet($this->_BIFF_version, $this->_writerWorksheets[$i] = new PHPExcel_Writer_Excel5_Worksheet($this->_str_total, $this->_str_unique,
$this->_str_total, $this->_str_unique, $this->_str_table, $this->_colors,
$this->_str_table, $this->_colors, $this->_parser,
$this->_parser, $this->_preCalculateFormulas,
$this->_preCalculateFormulas, $this->_phpExcel->getSheet($i));
$this->_phpExcel->getSheet($i));
} }
// build Escher objects. Escher objects for workbooks needs to be build before Escher object for workbook. // build Escher objects. Escher objects for workbooks needs to be build before Escher object for workbook.
@ -161,7 +161,7 @@ class PHPExcel_Writer_Excel5 implements PHPExcel_Writer_IWriter
} }
// initialize OLE file // initialize OLE file
$workbookStreamName = ($this->_BIFF_version == 0x0600) ? 'Workbook' : 'Book'; $workbookStreamName = 'Workbook';
$OLE = new PHPExcel_Shared_OLE_PPS_File(PHPExcel_Shared_OLE::Asc2Ucs($workbookStreamName)); $OLE = new PHPExcel_Shared_OLE_PPS_File(PHPExcel_Shared_OLE::Asc2Ucs($workbookStreamName));
// Write the worksheet streams before the global workbook stream, // Write the worksheet streams before the global workbook stream,

View File

@ -69,12 +69,6 @@
*/ */
class PHPExcel_Writer_Excel5_BIFFwriter class PHPExcel_Writer_Excel5_BIFFwriter
{ {
/**
* The BIFF/Excel version (5).
* @var integer
*/
public $_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 integer
@ -128,8 +122,7 @@ class PHPExcel_Writer_Excel5_BIFFwriter
$byte_order = 1; // Big Endian $byte_order = 1; // Big Endian
} else { } else {
// Give up. I'll fix this in a later version. // Give up. I'll fix this in a later version.
throw new Exception("Required floating point format ". throw new Exception("Required floating point format not supported on this platform.");
"not supported on this platform.");
} }
self::$_byte_order = $byte_order; self::$_byte_order = $byte_order;
} }
@ -179,24 +172,15 @@ class PHPExcel_Writer_Excel5_BIFFwriter
function _storeBof($type) function _storeBof($type)
{ {
$record = 0x0809; // Record identifier $record = 0x0809; // Record identifier
$length = 0x0010;
// According to the SDK $build and $year should be set to zero. // by inspection of real files, MS Office Excel 2007 writes the following
// However, this throws a warning in Excel 5. So, use magic numbers. $unknown = pack("VV", 0x000100D1, 0x00000406);
if ($this->_BIFF_version == 0x0500) {
$length = 0x0008;
$unknown = '';
$build = 0x096C;
$year = 0x07C9;
} elseif ($this->_BIFF_version == 0x0600) {
$length = 0x0010;
// by inspection of real files, MS Office Excel 2007 writes the following $build = 0x0DBB;
$unknown = pack("VV", 0x000100D1, 0x00000406); $year = 0x07CC;
$build = 0x0DBB; $version = 0x0600;
$year = 0x07CC;
}
$version = $this->_BIFF_version;
$header = pack("vv", $record, $length); $header = pack("vv", $record, $length);
$data = pack("vvvv", $version, $type, $build, $year); $data = pack("vvvv", $version, $type, $build, $year);
@ -212,6 +196,7 @@ class PHPExcel_Writer_Excel5_BIFFwriter
{ {
$record = 0x000A; // Record identifier $record = 0x000A; // Record identifier
$length = 0x0000; // Number of bytes to follow $length = 0x0000; // Number of bytes to follow
$header = pack("vv", $record, $length); $header = pack("vv", $record, $length);
$this->_append($header); $this->_append($header);
} }

View File

@ -35,13 +35,6 @@
*/ */
class PHPExcel_Writer_Excel5_Font class PHPExcel_Writer_Excel5_Font
{ {
/**
* BIFF version
*
* @var int
*/
private $_BIFFVersion;
/** /**
* Color index * Color index
* *
@ -63,7 +56,6 @@ class PHPExcel_Writer_Excel5_Font
*/ */
public function __construct(PHPExcel_Style_Font $font = null) public function __construct(PHPExcel_Style_Font $font = null)
{ {
$this->_BIFFVersion = 0x0600;
$this->_colorIndex = 0x7FFF; $this->_colorIndex = 0x7FFF;
$this->_font = $font; $this->_font = $font;
} }
@ -115,34 +107,18 @@ class PHPExcel_Writer_Excel5_Font
$grbit |= 0x20; $grbit |= 0x20;
} }
if ($this->_BIFFVersion == 0x0500) { $data = pack("vvvvvCCCC",
$data = pack("vvvvvCCCCC", $this->_font->getSize() * 20,
$this->_font->getSize() * 20, $grbit,
$grbit, $icv,
$icv, $this->_mapBold($this->_font->getBold()),
$this->_mapBold($this->_font->getBold()), $sss,
$sss, $this->_mapUnderline($this->_font->getUnderline()),
$this->_mapUnderline($this->_font->getUnderline()), $bFamily,
$bFamily, $bCharSet,
$bCharSet, $reserved
$reserved, );
strlen($this->_font->getName()) $data .= PHPExcel_Shared_String::UTF8toBIFF8UnicodeShort($this->_font->getName());
);
$data .= $this->_font->getName();
} elseif ($this->_BIFFVersion == 0x0600) {
$data = pack("vvvvvCCCC",
$this->_font->getSize() * 20,
$grbit,
$icv,
$this->_mapBold($this->_font->getBold()),
$sss,
$this->_mapUnderline($this->_font->getUnderline()),
$bFamily,
$bCharSet,
$reserved
);
$data .= PHPExcel_Shared_String::UTF8toBIFF8UnicodeShort($this->_font->getName());
}
$length = strlen($data); $length = strlen($data);
$header = pack("vv", $record, $length); $header = pack("vv", $record, $length);
@ -150,16 +126,6 @@ class PHPExcel_Writer_Excel5_Font
return($header . $data); return($header . $data);
} }
/**
* Set BIFF version
*
* @param int $BIFFVersion
*/
public function setBIFFVersion($BIFFVersion)
{
$this->_BIFFVersion = $BIFFVersion;
}
/** /**
* Map to BIFF5-BIFF8 codes for bold * Map to BIFF5-BIFF8 codes for bold
* *

View File

@ -115,22 +115,15 @@ class PHPExcel_Writer_Excel5_Parser
*/ */
public $_references; public $_references;
/**
* The BIFF version for the workbook
* @var integer
*/
public $_BIFF_version;
/** /**
* The class constructor * The class constructor
* *
* @param integer $byte_order The byte order (Little endian or Big endian) of the architecture * @param integer $byte_order The byte order (Little endian or Big endian) of the architecture
* (optional). 1 => big endian, 0 (default) little endian. * (optional). 1 => big endian, 0 (default) little endian.
*/ */
public function __construct($biff_version) public function __construct()
{ {
$this->_current_char = 0; $this->_current_char = 0;
$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.
@ -610,11 +603,7 @@ class PHPExcel_Writer_Excel5_Parser
throw new Exception("String is too long"); throw new Exception("String is too long");
} }
if ($this->_BIFF_version == 0x0500) { return pack('C', $this->ptg['ptgStr']) . PHPExcel_Shared_String::UTF8toBIFF8UnicodeShort($string);
return pack("CC", $this->ptg['ptgStr'], strlen($string)).$string;
} elseif ($this->_BIFF_version == 0x0600) {
return pack('C', $this->ptg['ptgStr']) . PHPExcel_Shared_String::UTF8toBIFF8UnicodeShort($string);
}
} }
/** /**
@ -695,11 +684,7 @@ class PHPExcel_Writer_Excel5_Parser
list($ext_ref, $range) = explode('!', $token); list($ext_ref, $range) = explode('!', $token);
// Convert the external reference part (different for BIFF8) // Convert the external reference part (different for BIFF8)
if ($this->_BIFF_version == 0x0500) { $ext_ref = $this->_getRefIndex($ext_ref);
$ext_ref = $this->_packExtRef($ext_ref);
} elseif ($this->_BIFF_version == 0x0600) {
$ext_ref = $this->_getRefIndex($ext_ref);
}
// Split the range into 2 cell refs // Split the range into 2 cell refs
list($cell1, $cell2) = explode(':', $range); list($cell1, $cell2) = explode(':', $range);
@ -774,11 +759,7 @@ class PHPExcel_Writer_Excel5_Parser
list($ext_ref, $cell) = explode('!', $cell); list($ext_ref, $cell) = explode('!', $cell);
// Convert the external reference part (different for BIFF8) // Convert the external reference part (different for BIFF8)
if ($this->_BIFF_version == 0x0500) { $ext_ref = $this->_getRefIndex($ext_ref);
$ext_ref = $this->_packExtRef($ext_ref);
} elseif ($this->_BIFF_version == 0x0600) {
$ext_ref = $this->_getRefIndex($ext_ref);
}
// Convert the cell reference part // Convert the cell reference part
list($row, $col) = $this->_cellToPackedRowcol($cell); list($row, $col) = $this->_cellToPackedRowcol($cell);
@ -973,16 +954,11 @@ class PHPExcel_Writer_Excel5_Parser
} }
// Set the high bits to indicate if row or col are relative. // Set the high bits to indicate if row or col are relative.
if ($this->_BIFF_version == 0x0500) { $col |= $col_rel << 14;
$row |= $col_rel << 14; $col |= $row_rel << 15;
$row |= $row_rel << 15; $col = pack('v', $col);
$col = pack('C', $col);
} elseif ($this->_BIFF_version == 0x0600) { $row = pack('v', $row);
$col |= $col_rel << 14;
$col |= $row_rel << 15;
$col = pack('v', $col);
}
$row = pack('v', $row);
return array($row, $col); return array($row, $col);
} }
@ -1016,19 +992,13 @@ class PHPExcel_Writer_Excel5_Parser
} }
// Set the high bits to indicate if rows are relative. // Set the high bits to indicate if rows are relative.
if ($this->_BIFF_version == 0x0500) { $col1 |= $row1_rel << 15;
$row1 |= $row1_rel << 14; // FIXME: probably a bug $col2 |= $row2_rel << 15;
$row2 |= $row2_rel << 15; $col1 = pack('v', $col1);
$col1 = pack('C', $col1); $col2 = pack('v', $col2);
$col2 = pack('C', $col2);
} elseif ($this->_BIFF_version == 0x0600) { $row1 = pack('v', $row1);
$col1 |= $row1_rel << 15; $row2 = pack('v', $row2);
$col2 |= $row2_rel << 15;
$col1 = pack('v', $col1);
$col2 = pack('v', $col2);
}
$row1 = pack('v', $row1);
$row2 = pack('v', $row2);
return array($row1, $col1, $row2, $col2); return array($row1, $col1, $row2, $col2);
} }

View File

@ -194,16 +194,14 @@ class PHPExcel_Writer_Excel5_Workbook extends PHPExcel_Writer_Excel5_BIFFwriter
* Class constructor * Class constructor
* *
* @param PHPExcel $phpExcel The Workbook * @param PHPExcel $phpExcel The Workbook
* @param int $BIFF_verions BIFF version
* @param int $str_total Total number of strings * @param int $str_total Total number of strings
* @param int $str_unique Total number of unique strings * @param int $str_unique Total number of unique strings
* @param array $str_table * @param array $str_table
* @param mixed $parser The formula parser created for the Workbook * @param mixed $parser The formula parser created for the Workbook
*/ */
public function __construct(PHPExcel $phpExcel = null, $BIFF_version = 0x0600, public function __construct(PHPExcel $phpExcel = null,
&$str_total, &$str_total, &$str_unique, &$str_table, &$colors,
&$str_unique, &$str_table, &$colors, $parser $parser )
)
{ {
// It needs to call its parent's constructor explicitly // It needs to call its parent's constructor explicitly
parent::__construct(); parent::__construct();
@ -211,7 +209,6 @@ class PHPExcel_Writer_Excel5_Workbook extends PHPExcel_Writer_Excel5_BIFFwriter
$this->_parser = $parser; $this->_parser = $parser;
$this->_biffsize = 0; $this->_biffsize = 0;
$this->_palette = array(); $this->_palette = array();
$this->_codepage = 0x04E4; // FIXME: should change for BIFF8
$this->_country_code = -1; $this->_country_code = -1;
$this->_str_total = &$str_total; $this->_str_total = &$str_total;
@ -222,12 +219,9 @@ class PHPExcel_Writer_Excel5_Workbook extends PHPExcel_Writer_Excel5_BIFFwriter
$this->_phpExcel = $phpExcel; $this->_phpExcel = $phpExcel;
if ($BIFF_version == 0x0600) { // set BIFFwriter limit for CONTINUE records
$this->_BIFF_version = 0x0600; $this->_limit = 8224;
// change BIFFwriter limit for CONTINUE records $this->_codepage = 0x04B0;
$this->_limit = 8224;
$this->_codepage = 0x04B0;
}
// Add empty sheets and Build color cache // Add empty sheets and Build color cache
$countSheets = $phpExcel->getSheetCount(); $countSheets = $phpExcel->getSheetCount();
@ -236,12 +230,10 @@ class PHPExcel_Writer_Excel5_Workbook extends PHPExcel_Writer_Excel5_BIFFwriter
$this->_parser->setExtSheet($phpSheet->getTitle(), $i); // Register worksheet name with parser $this->_parser->setExtSheet($phpSheet->getTitle(), $i); // Register worksheet name with parser
// for BIFF8 $supbook_index = 0x00;
if ($this->_BIFF_version == 0x0600) { $ref = pack('vvv', $supbook_index, $i, $i);
$supbook_index = 0x00; $this->_parser->_references[] = $ref; // Register reference with parser
$ref = pack('vvv', $supbook_index, $i, $i);
$this->_parser->_references[] = $ref; // Register reference with parser
}
// Sheet tab colors? // Sheet tab colors?
if ($phpSheet->isTabColorSet()) { if ($phpSheet->isTabColorSet()) {
$this->_addColor($phpSheet->getTabColor()->getRGB()); $this->_addColor($phpSheet->getTabColor()->getRGB());
@ -260,7 +252,6 @@ class PHPExcel_Writer_Excel5_Workbook extends PHPExcel_Writer_Excel5_BIFFwriter
public function addXfWriter($style, $isStyleXf = false) public function addXfWriter($style, $isStyleXf = false)
{ {
$xfWriter = new PHPExcel_Writer_Excel5_Xf($style); $xfWriter = new PHPExcel_Writer_Excel5_Xf($style);
$xfWriter->setBIFFVersion($this->_BIFF_version);
$xfWriter->setIsStyleXf($isStyleXf); $xfWriter->setIsStyleXf($isStyleXf);
// Add the font if not already added // Add the font if not already added
@ -273,7 +264,6 @@ class PHPExcel_Writer_Excel5_Workbook extends PHPExcel_Writer_Excel5_BIFFwriter
$fontIndex = ($countFonts < 4) ? $countFonts : $countFonts + 1; $fontIndex = ($countFonts < 4) ? $countFonts : $countFonts + 1;
$fontWriter = new PHPExcel_Writer_Excel5_Font($style->getFont()); $fontWriter = new PHPExcel_Writer_Excel5_Font($style->getFont());
$fontWriter->setBIFFVersion($this->_BIFF_version);
$fontWriter->setColorIndex($this->_addColor($style->getFont()->getColor()->getRGB())); $fontWriter->setColorIndex($this->_addColor($style->getFont()->getColor()->getRGB()));
$this->_fontWriters[] = $fontWriter; $this->_fontWriters[] = $fontWriter;
@ -433,16 +423,8 @@ class PHPExcel_Writer_Excel5_Workbook extends PHPExcel_Writer_Excel5_BIFFwriter
// Add part 1 of the Workbook globals, what goes before the SHEET records // Add part 1 of the Workbook globals, what goes before the SHEET records
$this->_storeBof(0x0005); $this->_storeBof(0x0005);
$this->_writeCodepage(); $this->_writeCodepage();
if ($this->_BIFF_version == 0x0600) { $this->_writeWindow1();
$this->_writeWindow1();
}
if ($this->_BIFF_version == 0x0500) {
$this->_writeExterns(); // For print area and repeat rows
$this->_writeNames(); // For print area and repeat rows
}
if ($this->_BIFF_version == 0x0500) {
$this->_writeWindow1();
}
$this->_writeDatemode(); $this->_writeDatemode();
$this->_writeAllFonts(); $this->_writeAllFonts();
$this->_writeAllNumFormats(); $this->_writeAllNumFormats();
@ -457,15 +439,13 @@ class PHPExcel_Writer_Excel5_Workbook extends PHPExcel_Writer_Excel5_BIFFwriter
} }
$part3 .= $this->_writeRecalcId(); $part3 .= $this->_writeRecalcId();
if ($this->_BIFF_version == 0x0600) { $part3 .= $this->_writeSupbookInternal();
$part3 .= $this->_writeSupbookInternal(); /* 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 */
in case of external references for BIFF8 */ $part3 .= $this->_writeExternsheetBiff8();
$part3 .= $this->_writeExternsheetBiff8(); $part3 .= $this->_writeAllDefinedNamesBiff8();
$part3 .= $this->_writeAllDefinedNamesBiff8(); $part3 .= $this->_writeMsoDrawingGroup();
$part3 .= $this->_writeMsoDrawingGroup(); $part3 .= $this->_writeSharedStringsTable();
$part3 .= $this->_writeSharedStringsTable();
}
$part3 .= $this->writeEof(); $part3 .= $this->writeEof();
@ -488,11 +468,7 @@ class PHPExcel_Writer_Excel5_Workbook extends PHPExcel_Writer_Excel5_BIFFwriter
*/ */
function _calcSheetOffsets() function _calcSheetOffsets()
{ {
if ($this->_BIFF_version == 0x0600) { $boundsheet_length = 10; // fixed length for a BOUNDSHEET record
$boundsheet_length = 10; // fixed length for a BOUNDSHEET record
} else {
$boundsheet_length = 11;
}
// size of Workbook globals part 1 + 3 // size of Workbook globals part 1 + 3
$offset = $this->_datasize; $offset = $this->_datasize;
@ -500,11 +476,7 @@ class PHPExcel_Writer_Excel5_Workbook extends PHPExcel_Writer_Excel5_BIFFwriter
// add size of Workbook globals part 2, the length of the SHEET records // add size of Workbook globals part 2, the length of the SHEET records
$total_worksheets = count($this->_phpExcel->getAllSheets()); $total_worksheets = count($this->_phpExcel->getAllSheets());
foreach ($this->_phpExcel->getWorksheetIterator() as $sheet) { foreach ($this->_phpExcel->getWorksheetIterator() as $sheet) {
if ($this->_BIFF_version == 0x0600) { $offset += $boundsheet_length + strlen(PHPExcel_Shared_String::UTF8toBIFF8UnicodeShort($sheet->getTitle()));
$offset += $boundsheet_length + strlen(PHPExcel_Shared_String::UTF8toBIFF8UnicodeShort($sheet->getTitle()));
} else {
$offset += $boundsheet_length + strlen($sheet->getTitle());
}
} }
// add the sizes of each of the Sheet substreams, respectively // add the sizes of each of the Sheet substreams, respectively
@ -908,14 +880,8 @@ class PHPExcel_Writer_Excel5_Workbook extends PHPExcel_Writer_Excel5_BIFFwriter
$grbit = 0x0000; // Visibility and sheet type $grbit = 0x0000; // Visibility and sheet type
if ($this->_BIFF_version == 0x0600) { $data = pack("VCC", $offset, $ss, $st);
$data = pack("VCC", $offset, $ss, $st); $data .= PHPExcel_Shared_String::UTF8toBIFF8UnicodeShort($sheetname);
$data .= PHPExcel_Shared_String::UTF8toBIFF8UnicodeShort($sheetname);
} else {
$cch = strlen($sheetname); // Length of sheet name
$data = pack("VCCC", $offset, $ss, $st, $cch);
$data .= $sheetname;
}
$length = strlen($data); $length = strlen($data);
$header = pack("vv", $record, $length); $header = pack("vv", $record, $length);
@ -983,23 +949,13 @@ class PHPExcel_Writer_Excel5_Workbook extends PHPExcel_Writer_Excel5_BIFFwriter
{ {
$record = 0x041E; // Record identifier $record = 0x041E; // Record identifier
if ($this->_BIFF_version == 0x0600) { $numberFormatString = PHPExcel_Shared_String::UTF8toBIFF8UnicodeLong($format);
$numberFormatString = PHPExcel_Shared_String::UTF8toBIFF8UnicodeLong($format); $length = 2 + strlen($numberFormatString); // Number of bytes to follow
$length = 2 + strlen($numberFormatString); // Number of bytes to follow
} elseif ($this->_BIFF_version == 0x0500) {
$length = 3 + strlen($format); // Number of bytes to follow
}
$header = pack("vv", $record, $length); $header = pack("vv", $record, $length);
if ($this->_BIFF_version == 0x0600) { $data = pack("v", $ifmt) . $numberFormatString;
$data = pack("v", $ifmt) . $numberFormatString; $this->_append($header . $data);
$this->_append($header . $data);
} elseif ($this->_BIFF_version == 0x0500) {
$cch = strlen($format); // Length of format string
$data = pack("vC", $ifmt, $cch);
$this->_append($header . $data . $format);
}
} }
/** /**

View File

@ -195,7 +195,6 @@ class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter
/** /**
* Constructor * Constructor
* *
* @param int $BIFF_version BIFF version
* @param int $str_total Total number of strings * @param int $str_total Total number of strings
* @param int $str_unique Total number of unique strings * @param int $str_unique Total number of unique strings
* @param array $str_table * @param array $str_table
@ -203,19 +202,14 @@ class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter
* @param string $tempDir The temporary directory to be used * @param string $tempDir The temporary directory to be used
* @param PHPExcel_Worksheet $phpSheet * @param PHPExcel_Worksheet $phpSheet
*/ */
public function __construct($BIFF_version, public function __construct(&$str_total, &$str_unique, &$str_table, &$colors,
&$str_total, $parser, $preCalculateFormulas, $phpSheet)
&$str_unique, &$str_table, &$colors,
$parser, $preCalculateFormulas, $phpSheet)
{ {
// It needs to call its parent's constructor explicitly // It needs to call its parent's constructor explicitly
parent::__construct(); parent::__construct();
$this->_BIFF_version = $BIFF_version; // change BIFFwriter limit for CONTINUE records
if ($BIFF_version == 0x0600) { $this->_limit = 8224;
// change BIFFwriter limit for CONTINUE records
$this->_limit = 8224;
}
$this->_preCalculateFormulas = $preCalculateFormulas; $this->_preCalculateFormulas = $preCalculateFormulas;
@ -328,9 +322,7 @@ class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter
$this->_writeGuts(); $this->_writeGuts();
// Write DEFAULTROWHEIGHT // Write DEFAULTROWHEIGHT
if ($this->_BIFF_version == 0x0600) { $this->_writeDefaultRowHeight();
$this->_writeDefaultRowHeight();
}
// Write WSBOOL // Write WSBOOL
$this->_writeWsbool(); $this->_writeWsbool();
@ -388,18 +380,6 @@ class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter
} }
} }
// Write EXTERNCOUNT of external references
if ($this->_BIFF_version == 0x0500) {
$this->_writeExterncount($num_sheets);
}
// Write EXTERNSHEET references
if ($this->_BIFF_version == 0x0500) {
for ($i = 0; $i < $num_sheets; ++$i) {
$this->_writeExternsheet($this->_phpSheet->getParent()->getSheet($i)->getTitle());
}
}
// Write sheet dimensions // Write sheet dimensions
$this->_writeDimensions(); $this->_writeDimensions();
@ -458,9 +438,8 @@ class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter
} }
// Append // Append
if ($this->_BIFF_version == 0x0600) { $this->_writeMsoDrawing();
$this->_writeMsoDrawing();
}
$this->_writeWindow2(); $this->_writeWindow2();
$this->_writeZoom(); $this->_writeZoom();
if ($this->_phpSheet->getFreezePane()) { if ($this->_phpSheet->getFreezePane()) {
@ -470,35 +449,31 @@ class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter
$this->_writeMergedCells(); $this->_writeMergedCells();
// Hyperlinks // Hyperlinks
if ($this->_BIFF_version == 0x0600) { foreach ($this->_phpSheet->getHyperLinkCollection() as $coordinate => $hyperlink) {
foreach ($this->_phpSheet->getHyperLinkCollection() as $coordinate => $hyperlink) { list($column, $row) = PHPExcel_Cell::coordinateFromString($coordinate);
list($column, $row) = PHPExcel_Cell::coordinateFromString($coordinate);
$url = $hyperlink->getUrl(); $url = $hyperlink->getUrl();
if ( strpos($url, 'sheet://') !== false ) { if ( strpos($url, 'sheet://') !== false ) {
// internal to current workbook // internal to current workbook
$url = str_replace('sheet://', 'internal:', $url); $url = str_replace('sheet://', 'internal:', $url);
} else if ( preg_match('/^(http:|https:|ftp:|mailto:)/', $url) ) { } else if ( preg_match('/^(http:|https:|ftp:|mailto:)/', $url) ) {
// URL // URL
// $url = $url; // $url = $url;
} else { } else {
// external (local file) // external (local file)
$url = 'external:' . $url; $url = 'external:' . $url;
}
$this->_writeUrl($row - 1, PHPExcel_Cell::columnIndexFromString($column) - 1, $url);
} }
$this->_writeUrl($row - 1, PHPExcel_Cell::columnIndexFromString($column) - 1, $url);
} }
if ($this->_BIFF_version == 0x0600) { $this->_writeDataValidity();
$this->_writeDataValidity(); $this->_writeSheetLayout();
$this->_writeSheetLayout(); $this->_writeSheetProtection();
$this->_writeSheetProtection(); $this->_writeRangeProtection();
$this->_writeRangeProtection();
}
$this->_storeEof(); $this->_storeEof();
} }
@ -608,10 +583,10 @@ class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter
$record = 0x0203; // Record identifier $record = 0x0203; // Record identifier
$length = 0x000E; // Number of bytes to follow $length = 0x000E; // Number of bytes to follow
$header = pack("vv", $record, $length); $header = pack("vv", $record, $length);
$data = pack("vvv", $row, $col, $xfIndex); $data = pack("vvv", $row, $col, $xfIndex);
$xl_double = pack("d", $num); $xl_double = pack("d", $num);
if (PHPExcel_Writer_Excel5_BIFFwriter::getByteOrder()) { // if it's Big Endian if (self::getByteOrder()) { // if it's Big Endian
$xl_double = strrev($xl_double); $xl_double = strrev($xl_double);
} }
@ -629,12 +604,9 @@ class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter
*/ */
private function _writeString($row, $col, $str, $xfIndex) private function _writeString($row, $col, $str, $xfIndex)
{ {
if ($this->_BIFF_version == 0x0600) { $this->_writeLabelSst($row, $col, $str, $xfIndex);
$this->_writeLabelSst($row, $col, $str, $xfIndex);
} else {
$this->_writeLabel($row, $col, $str, $xfIndex);
}
} }
/** /**
* Write a string to the specified row and column (zero indexed). * Write a string to the specified row and column (zero indexed).
* NOTE: there is an Excel 5 defined limit of 255 characters. * NOTE: there is an Excel 5 defined limit of 255 characters.
@ -659,14 +631,14 @@ class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter
$str_error = 0; $str_error = 0;
if ($strlen > $this->_xls_strmax) { // LABEL must be < 255 chars if ($strlen > $this->_xls_strmax) { // LABEL must be < 255 chars
$str = substr($str, 0, $this->_xls_strmax); $str = substr($str, 0, $this->_xls_strmax);
$length = 0x0008 + $this->_xls_strmax; $length = 0x0008 + $this->_xls_strmax;
$strlen = $this->_xls_strmax; $strlen = $this->_xls_strmax;
$str_error = -3; $str_error = -3;
} }
$header = pack("vv", $record, $length); $header = pack("vv", $record, $length);
$data = pack("vvvv", $row, $col, $xfIndex, $strlen); $data = pack("vvvv", $row, $col, $xfIndex, $strlen);
$this->_append($header . $data . $str); $this->_append($header . $data . $str);
return($str_error); return($str_error);
} }
@ -700,7 +672,7 @@ class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter
$this->_str_total++; $this->_str_total++;
$header = pack('vv', $record, $length); $header = pack('vv', $record, $length);
$data = pack('vvvV', $row, $col, $xfIndex, $this->_str_table[$str]); $data = pack('vvvV', $row, $col, $xfIndex, $this->_str_table[$str]);
$this->_append($header.$data); $this->_append($header.$data);
} }
@ -715,14 +687,13 @@ class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter
private function _writeNote($row, $col, $note) private function _writeNote($row, $col, $note)
{ {
$note_length = strlen($note); $note_length = strlen($note);
$record = 0x001C; // Record identifier $record = 0x001C; // Record identifier
$max_length = 2048; // Maximun length for a NOTE record $max_length = 2048; // Maximun length for a NOTE record
//$length = 0x0006 + $note_length; // Bytes to follow
// Length for this record is no more than 2048 + 6 // Length for this record is no more than 2048 + 6
$length = 0x0006 + min($note_length, 2048); $length = 0x0006 + min($note_length, 2048);
$header = pack("vv", $record, $length); $header = pack("vv", $record, $length);
$data = pack("vvv", $row, $col, $note_length); $data = pack("vvv", $row, $col, $note_length);
$this->_append($header . $data . substr($note, 0, 2048)); $this->_append($header . $data . substr($note, 0, 2048));
for ($i = $max_length; $i < $note_length; $i += $max_length) { for ($i = $max_length; $i < $note_length; $i += $max_length) {
@ -807,46 +778,36 @@ class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter
// calculated value // calculated value
if (isset($calculatedValue)) { if (isset($calculatedValue)) {
// Since we can't yet get the data type of the calculated value, // Since we can't yet get the data type of the calculated value,
// we use best effort to determine data type // we use best effort to determine data type
if (is_bool($calculatedValue)) { if (is_bool($calculatedValue)) {
// Boolean value // Boolean value
$num = pack('CCCvCv', 0x01, 0x00, (int)$calculatedValue, 0x00, 0x00, 0xFFFF); $num = pack('CCCvCv', 0x01, 0x00, (int)$calculatedValue, 0x00, 0x00, 0xFFFF);
} elseif (is_int($calculatedValue) || is_float($calculatedValue)) { } elseif (is_int($calculatedValue) || is_float($calculatedValue)) {
// Numeric value // Numeric value
$num = pack('d', $calculatedValue); $num = pack('d', $calculatedValue);
} elseif (is_string($calculatedValue)) { } elseif (is_string($calculatedValue)) {
if (array_key_exists($calculatedValue, PHPExcel_Cell_DataType::getErrorCodes())) { if (array_key_exists($calculatedValue, PHPExcel_Cell_DataType::getErrorCodes())) {
// Error value // Error value
$num = pack('CCCvCv', 0x02, 0x00, $this->_mapErrorCode($calculatedValue), 0x00, 0x00, 0xFFFF); $num = pack('CCCvCv', 0x02, 0x00, $this->_mapErrorCode($calculatedValue), 0x00, 0x00, 0xFFFF);
} elseif ($calculatedValue === '') {
} elseif ($calculatedValue === '' && $this->_BIFF_version == 0x0600) {
// Empty string (and BIFF8) // Empty string (and BIFF8)
$num = pack('CCCvCv', 0x03, 0x00, 0x00, 0x00, 0x00, 0xFFFF); $num = pack('CCCvCv', 0x03, 0x00, 0x00, 0x00, 0x00, 0xFFFF);
} else { } else {
// Non-empty string value (or empty string BIFF5) // Non-empty string value (or empty string BIFF5)
$stringValue = $calculatedValue; $stringValue = $calculatedValue;
$num = pack('CCCvCv', 0x00, 0x00, 0x00, 0x00, 0x00, 0xFFFF); $num = pack('CCCvCv', 0x00, 0x00, 0x00, 0x00, 0x00, 0xFFFF);
} }
} else { } else {
// We are really not supposed to reach here // We are really not supposed to reach here
$num = pack('d', 0x00); $num = pack('d', 0x00);
} }
} else { } else {
$num = pack('d', 0x00); $num = pack('d', 0x00);
} }
$grbit = 0x03; // Option flags $grbit = 0x03; // Option flags
$unknown = 0x0000; // Must be zero $unknown = 0x0000; // Must be zero
// Strip the '=' or '@' sign at the beginning of the formula string // Strip the '=' or '@' sign at the beginning of the formula string
if ($formula{0} == '=') { if ($formula{0} == '=') {
@ -1218,26 +1179,14 @@ class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter
{ {
$record = 0x0200; // Record identifier $record = 0x0200; // Record identifier
if ($this->_BIFF_version == 0x0500) { $length = 0x000E;
$length = 0x000A; // Number of bytes to follow $data = pack('VVvvv'
$data = pack("vvvvv" , $this->_firstRowIndex
, $this->_firstRowIndex , $this->_lastRowIndex + 1
, $this->_lastRowIndex + 1 , $this->_firstColumnIndex
, $this->_firstColumnIndex , $this->_lastColumnIndex + 1
, $this->_lastColumnIndex + 1 , 0x0000 // reserved
, 0x0000 // reserved );
);
} elseif ($this->_BIFF_version == 0x0600) {
$length = 0x000E;
$data = pack('VVvvv'
, $this->_firstRowIndex
, $this->_lastRowIndex + 1
, $this->_firstColumnIndex
, $this->_lastColumnIndex + 1
, 0x0000 // reserved
);
}
$header = pack("vv", $record, $length); $header = pack("vv", $record, $length);
$this->_append($header.$data); $this->_append($header.$data);
@ -1249,11 +1198,7 @@ class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter
private function _writeWindow2() private function _writeWindow2()
{ {
$record = 0x023E; // Record identifier $record = 0x023E; // Record identifier
if ($this->_BIFF_version == 0x0500) { $length = 0x0012;
$length = 0x000A; // Number of bytes to follow
} elseif ($this->_BIFF_version == 0x0600) {
$length = 0x0012;
}
$grbit = 0x00B6; // Option flags $grbit = 0x00B6; // Option flags
$rwTop = 0x0000; // Top row visible in window $rwTop = 0x0000; // Top row visible in window
@ -1288,16 +1233,13 @@ class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter
$header = pack("vv", $record, $length); $header = pack("vv", $record, $length);
$data = pack("vvv", $grbit, $rwTop, $colLeft); $data = pack("vvv", $grbit, $rwTop, $colLeft);
// FIXME !!! // FIXME !!!
if ($this->_BIFF_version == 0x0500) { $rgbHdr = 0x0040; // Row/column heading and gridline color index
$rgbHdr = 0x00000000; // Row/column heading and gridline color $zoom_factor_page_break = 0x0000;
$data .= pack("V", $rgbHdr); $zoom_factor_normal = 0x0000;
} elseif ($this->_BIFF_version == 0x0600) { $data .= pack("vvvvV", $rgbHdr, 0x0000, $zoom_factor_page_break, $zoom_factor_normal, 0x00000000);
$rgbHdr = 0x0040; // Row/column heading and gridline color index
$zoom_factor_page_break = 0x0000;
$zoom_factor_normal = 0x0000;
$data .= pack("vvvvV", $rgbHdr, 0x0000, $zoom_factor_page_break, $zoom_factor_normal, 0x00000000);
}
$this->_append($header.$data); $this->_append($header.$data);
} }
@ -1424,13 +1366,9 @@ class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter
// make sure we are not out of bounds // make sure we are not out of bounds
$colFirst = min($colFirst, 255); $colFirst = min($colFirst, 255);
$colLast = min($colLast, 255); $colLast = min($colLast, 255);
if ($this->_BIFF_version == 0x0600) {
$rwFirst = min($rwFirst, 65535); $rwFirst = min($rwFirst, 65535);
$rwLast = min($rwLast, 65535); $rwLast = min($rwLast, 65535);
} else {
$rwFirst = min($rwFirst, 16383);
$rwLast = min($rwLast, 16383);
}
$record = 0x001D; // Record identifier $record = 0x001D; // Record identifier
$length = 0x000F; // Number of bytes to follow $length = 0x000F; // Number of bytes to follow
@ -1478,11 +1416,7 @@ class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter
} }
// maximum allowed number of merged cells per record // maximum allowed number of merged cells per record
if ($this->_BIFF_version == 0x0600) { $maxCountMergeCellsPerRecord = 1027;
$maxCountMergeCellsPerRecord = 1027;
} else {
$maxCountMergeCellsPerRecord = 259;
}
// record identifier // record identifier
$record = 0x00E5; $record = 0x00E5;
@ -1827,7 +1761,7 @@ class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter
$numHdr = pack("d", $numHdr); $numHdr = pack("d", $numHdr);
$numFtr = pack("d", $numFtr); $numFtr = pack("d", $numFtr);
if (PHPExcel_Writer_Excel5_BIFFwriter::getByteOrder()) { // if it's Big Endian if (self::getByteOrder()) { // if it's Big Endian
$numHdr = strrev($numHdr); $numHdr = strrev($numHdr);
$numFtr = strrev($numFtr); $numFtr = strrev($numFtr);
} }
@ -1862,15 +1796,8 @@ class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter
} }
*/ */
if ($this->_BIFF_version == 0x0600) { $recordData = PHPExcel_Shared_String::UTF8toBIFF8UnicodeLong($this->_phpSheet->getHeaderFooter()->getOddHeader());
$recordData = PHPExcel_Shared_String::UTF8toBIFF8UnicodeLong($this->_phpSheet->getHeaderFooter()->getOddHeader()); $length = strlen($recordData);
$length = strlen($recordData);
} else {
$cch = strlen($this->_phpSheet->getHeaderFooter()->getOddHeader()); // Length of header string
$length = 1 + $cch; // Bytes to follow
$data = pack("C", $cch);
$recordData = $data . $this->_phpSheet->getHeaderFooter()->getOddHeader();
}
$header = pack("vv", $record, $length); $header = pack("vv", $record, $length);
@ -1893,15 +1820,8 @@ class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter
} }
*/ */
if ($this->_BIFF_version == 0x0600) { $recordData = PHPExcel_Shared_String::UTF8toBIFF8UnicodeLong($this->_phpSheet->getHeaderFooter()->getOddFooter());
$recordData = PHPExcel_Shared_String::UTF8toBIFF8UnicodeLong($this->_phpSheet->getHeaderFooter()->getOddFooter()); $length = strlen($recordData);
$length = strlen($recordData);
} else {
$cch = strlen($this->_phpSheet->getHeaderFooter()->getOddFooter()); // Length of footer string
$length = 1 + $cch;
$data = pack("C", $cch);
$recordData = $data . $this->_phpSheet->getHeaderFooter()->getOddFooter();
}
$header = pack("vv", $record, $length); $header = pack("vv", $record, $length);
@ -1953,7 +1873,7 @@ class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter
$header = pack("vv", $record, $length); $header = pack("vv", $record, $length);
$data = pack("d", $margin); $data = pack("d", $margin);
if (PHPExcel_Writer_Excel5_BIFFwriter::getByteOrder()) { // if it's Big Endian if (self::getByteOrder()) { // if it's Big Endian
$data = strrev($data); $data = strrev($data);
} }
@ -1972,7 +1892,7 @@ class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter
$header = pack("vv", $record, $length); $header = pack("vv", $record, $length);
$data = pack("d", $margin); $data = pack("d", $margin);
if (PHPExcel_Writer_Excel5_BIFFwriter::getByteOrder()) { // if it's Big Endian if (self::getByteOrder()) { // if it's Big Endian
$data = strrev($data); $data = strrev($data);
} }
@ -1991,7 +1911,7 @@ class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter
$header = pack("vv", $record, $length); $header = pack("vv", $record, $length);
$data = pack("d", $margin); $data = pack("d", $margin);
if (PHPExcel_Writer_Excel5_BIFFwriter::getByteOrder()) { // if it's Big Endian if (self::getByteOrder()) { // if it's Big Endian
$data = strrev($data); $data = strrev($data);
} }
@ -2010,7 +1930,7 @@ class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter
$header = pack("vv", $record, $length); $header = pack("vv", $record, $length);
$data = pack("d", $margin); $data = pack("d", $margin);
if (PHPExcel_Writer_Excel5_BIFFwriter::getByteOrder()) { // if it's Big Endian if (self::getByteOrder()) { // if it's Big Endian
$data = strrev($data); $data = strrev($data);
} }
@ -2191,22 +2111,14 @@ class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter
$record = 0x001b; // Record identifier $record = 0x001b; // Record identifier
$cbrk = count($hbreaks); // Number of page breaks $cbrk = count($hbreaks); // Number of page breaks
if ($this->_BIFF_version == 0x0600) { $length = 2 + 6 * $cbrk; // Bytes to follow
$length = 2 + 6 * $cbrk; // Bytes to follow
} else {
$length = 2 + 2 * $cbrk; // Bytes to follow
}
$header = pack("vv", $record, $length); $header = pack("vv", $record, $length);
$data = pack("v", $cbrk); $data = pack("v", $cbrk);
// Append each page break // Append each page break
foreach ($hbreaks as $hbreak) { foreach ($hbreaks as $hbreak) {
if ($this->_BIFF_version == 0x0600) { $data .= pack("vvv", $hbreak, 0x0000, 0x00ff);
$data .= pack("vvv", $hbreak, 0x0000, 0x00ff);
} else {
$data .= pack("v", $hbreak);
}
} }
$this->_append($header . $data); $this->_append($header . $data);
@ -2227,22 +2139,14 @@ class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter
$record = 0x001a; // Record identifier $record = 0x001a; // Record identifier
$cbrk = count($vbreaks); // Number of page breaks $cbrk = count($vbreaks); // Number of page breaks
if ($this->_BIFF_version == 0x0600) { $length = 2 + 6 * $cbrk; // Bytes to follow
$length = 2 + 6 * $cbrk; // Bytes to follow
} else {
$length = 2 + 2 * $cbrk; // Bytes to follow
}
$header = pack("vv", $record, $length); $header = pack("vv", $record, $length);
$data = pack("v", $cbrk); $data = pack("v", $cbrk);
// Append each page break // Append each page break
foreach ($vbreaks as $vbreak) { foreach ($vbreaks as $vbreak) {
if ($this->_BIFF_version == 0x0600) { $data .= pack("vvv", $vbreak, 0x0000, 0xffff);
$data .= pack("vvv", $vbreak, 0x0000, 0xffff);
} else {
$data .= pack("v", $vbreak);
}
} }
$this->_append($header . $data); $this->_append($header . $data);

View File

@ -70,13 +70,6 @@
*/ */
class PHPExcel_Writer_Excel5_Xf class PHPExcel_Writer_Excel5_Xf
{ {
/**
* BIFF version
*
* @var int
*/
private $_BIFFVersion;
/** /**
* Style XF or a cell XF ? * Style XF or a cell XF ?
* *
@ -148,7 +141,6 @@ class PHPExcel_Writer_Excel5_Xf
public function __construct(PHPExcel_Style $style = null) public function __construct(PHPExcel_Style $style = null)
{ {
$this->_isStyleXf = false; $this->_isStyleXf = false;
$this->_BIFFVersion = 0x0600;
$this->_fontIndex = 0; $this->_fontIndex = 0;
$this->_numberFormatIndex = 0; $this->_numberFormatIndex = 0;
@ -218,112 +210,64 @@ class PHPExcel_Writer_Excel5_Xf
} }
$record = 0x00E0; // Record identifier $record = 0x00E0; // Record identifier
if ($this->_BIFFVersion == 0x0500) { $length = 0x0014; // Number of bytes to follow
$length = 0x0010; // Number of bytes to follow
}
if ($this->_BIFFVersion == 0x0600) {
$length = 0x0014;
}
$ifnt = $this->_fontIndex; // Index to FONT record $ifnt = $this->_fontIndex; // Index to FONT record
$ifmt = $this->_numberFormatIndex; // Index to FORMAT record $ifmt = $this->_numberFormatIndex; // Index to FORMAT record
if ($this->_BIFFVersion == 0x0500) {
$align = $this->_mapHAlign($this->_style->getAlignment()->getHorizontal()); // Alignment
$align |= (int) $this->_style->getAlignment()->getWrapText() << 3;
$align |= $this->_mapVAlign($this->_style->getAlignment()->getVertical()) << 4;
$align |= $this->_text_justlast << 7;
$align |= 0 << 8; // rotation
$align |= $atr_num << 10;
$align |= $atr_fnt << 11;
$align |= $atr_alc << 12;
$align |= $atr_bdr << 13;
$align |= $atr_pat << 14;
$align |= $atr_prot << 15;
$icv = $this->_fg_color; // fg and bg pattern colors $align = $this->_mapHAlign($this->_style->getAlignment()->getHorizontal()); // Alignment
$icv |= $this->_bg_color << 7; $align |= (int) $this->_style->getAlignment()->getWrapText() << 3;
$align |= $this->_mapVAlign($this->_style->getAlignment()->getVertical()) << 4;
$align |= $this->_text_justlast << 7;
$fill = $this->_mapFillType($this->_style->getFill()->getFillType()); // Fill and border line style $used_attrib = $atr_num << 2;
$fill |= $this->_mapBorderStyle($this->_style->getBorders()->getBottom()->getBorderStyle()) << 6; $used_attrib |= $atr_fnt << 3;
$fill |= $this->_bottom_color << 9; $used_attrib |= $atr_alc << 4;
$used_attrib |= $atr_bdr << 5;
$used_attrib |= $atr_pat << 6;
$used_attrib |= $atr_prot << 7;
$border1 = $this->_mapBorderStyle($this->_style->getBorders()->getTop()->getBorderStyle()); // Border line style and color $icv = $this->_fg_color; // fg and bg pattern colors
$border1 |= $this->_mapBorderStyle($this->_style->getBorders()->getLeft()->getBorderStyle()) << 3; $icv |= $this->_bg_color << 7;
$border1 |= $this->_mapBorderStyle($this->_style->getBorders()->getRight()->getBorderStyle()) << 6;
$border1 |= $this->_top_color << 9;
$border2 = $this->_left_color; // Border color $border1 = $this->_mapBorderStyle($this->_style->getBorders()->getLeft()->getBorderStyle()); // Border line style and color
$border2 |= $this->_right_color << 7; $border1 |= $this->_mapBorderStyle($this->_style->getBorders()->getRight()->getBorderStyle()) << 4;
$border1 |= $this->_mapBorderStyle($this->_style->getBorders()->getTop()->getBorderStyle()) << 8;
$border1 |= $this->_mapBorderStyle($this->_style->getBorders()->getBottom()->getBorderStyle()) << 12;
$border1 |= $this->_left_color << 16;
$border1 |= $this->_right_color << 23;
$header = pack("vv", $record, $length); $diagonalDirection = $this->_style->getBorders()->getDiagonalDirection();
$data = pack("vvvvvvvv", $ifnt, $ifmt, $style, $align, $diag_tl_to_rb = $diagonalDirection == PHPExcel_Style_Borders::DIAGONAL_BOTH
$icv, $fill, || $diagonalDirection == PHPExcel_Style_Borders::DIAGONAL_DOWN;
$border1, $border2); $diag_tr_to_lb = $diagonalDirection == PHPExcel_Style_Borders::DIAGONAL_BOTH
} elseif ($this->_BIFFVersion == 0x0600) { || $diagonalDirection == PHPExcel_Style_Borders::DIAGONAL_UP;
$align = $this->_mapHAlign($this->_style->getAlignment()->getHorizontal()); // Alignment $border1 |= $diag_tl_to_rb << 30;
$align |= (int) $this->_style->getAlignment()->getWrapText() << 3; $border1 |= $diag_tr_to_lb << 31;
$align |= $this->_mapVAlign($this->_style->getAlignment()->getVertical()) << 4;
$align |= $this->_text_justlast << 7;
$used_attrib = $atr_num << 2; $border2 = $this->_top_color; // Border color
$used_attrib |= $atr_fnt << 3; $border2 |= $this->_bottom_color << 7;
$used_attrib |= $atr_alc << 4; $border2 |= $this->_diag_color << 14;
$used_attrib |= $atr_bdr << 5; $border2 |= $this->_mapBorderStyle($this->_style->getBorders()->getDiagonal()->getBorderStyle()) << 21;
$used_attrib |= $atr_pat << 6; $border2 |= $this->_mapFillType($this->_style->getFill()->getFillType()) << 26;
$used_attrib |= $atr_prot << 7;
$icv = $this->_fg_color; // fg and bg pattern colors $header = pack("vv", $record, $length);
$icv |= $this->_bg_color << 7;
$border1 = $this->_mapBorderStyle($this->_style->getBorders()->getLeft()->getBorderStyle()); // Border line style and color //BIFF8 options: identation, shrinkToFit and text direction
$border1 |= $this->_mapBorderStyle($this->_style->getBorders()->getRight()->getBorderStyle()) << 4; $biff8_options = $this->_style->getAlignment()->getIndent();
$border1 |= $this->_mapBorderStyle($this->_style->getBorders()->getTop()->getBorderStyle()) << 8; $biff8_options |= (int) $this->_style->getAlignment()->getShrinkToFit() << 4;
$border1 |= $this->_mapBorderStyle($this->_style->getBorders()->getBottom()->getBorderStyle()) << 12;
$border1 |= $this->_left_color << 16;
$border1 |= $this->_right_color << 23;
$diagonalDirection = $this->_style->getBorders()->getDiagonalDirection(); $data = pack("vvvC", $ifnt, $ifmt, $style, $align);
$diag_tl_to_rb = $diagonalDirection == PHPExcel_Style_Borders::DIAGONAL_BOTH $data .= pack("CCC"
|| $diagonalDirection == PHPExcel_Style_Borders::DIAGONAL_DOWN; , $this->_mapTextRotation($this->_style->getAlignment()->getTextRotation())
$diag_tr_to_lb = $diagonalDirection == PHPExcel_Style_Borders::DIAGONAL_BOTH , $biff8_options
|| $diagonalDirection == PHPExcel_Style_Borders::DIAGONAL_UP; , $used_attrib
$border1 |= $diag_tl_to_rb << 30; );
$border1 |= $diag_tr_to_lb << 31; $data .= pack("VVv", $border1, $border2, $icv);
$border2 = $this->_top_color; // Border color
$border2 |= $this->_bottom_color << 7;
$border2 |= $this->_diag_color << 14;
$border2 |= $this->_mapBorderStyle($this->_style->getBorders()->getDiagonal()->getBorderStyle()) << 21;
$border2 |= $this->_mapFillType($this->_style->getFill()->getFillType()) << 26;
$header = pack("vv", $record, $length);
//BIFF8 options: identation, shrinkToFit and text direction
$biff8_options = $this->_style->getAlignment()->getIndent();
$biff8_options |= (int) $this->_style->getAlignment()->getShrinkToFit() << 4;
$data = pack("vvvC", $ifnt, $ifmt, $style, $align);
$data .= pack("CCC"
, $this->_mapTextRotation($this->_style->getAlignment()->getTextRotation())
, $biff8_options
, $used_attrib
);
$data .= pack("VVv", $border1, $border2, $icv);
}
return($header . $data); return($header . $data);
} }
/**
* Set BIFF version
*
* @param int $BIFFVersion
*/
public function setBIFFVersion($BIFFVersion)
{
$this->_BIFFVersion = $BIFFVersion;
}
/** /**
* Is this a style XF ? * Is this a style XF ?
* *