From bb34668146b7c892769ecad33b5edf5cc2ac5800 Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Fri, 5 Aug 2011 14:04:07 +0000 Subject: [PATCH] Modify underlying PHP_OLE to support multiple streams This is preparatory to providing support for workbook properties (and extended properties) in the Excel5 Writer, because properties are stored in the SummaryInformation and DocumentSummaryInformation streams, and not in the workbook stream. Previously, PHP_OLE could only save a single stream, so this had to be the workbook stream; so document property information was discarded by the Excel5 Writer. git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@77804 2327b42d-5241-43d6-9e2a-de5ac946f064 --- Classes/PHPExcel/Shared/OLE/PPS.php | 34 ++++++++++++------ Classes/PHPExcel/Shared/OLE/PPS/Root.php | 44 ++++++++++++------------ 2 files changed, 46 insertions(+), 32 deletions(-) diff --git a/Classes/PHPExcel/Shared/OLE/PPS.php b/Classes/PHPExcel/Shared/OLE/PPS.php index e3d4673..60b815a 100644 --- a/Classes/PHPExcel/Shared/OLE/PPS.php +++ b/Classes/PHPExcel/Shared/OLE/PPS.php @@ -196,21 +196,35 @@ class PHPExcel_Shared_OLE_PPS * PPS. I don't think it'll work with Dir PPS's. * * @access public - * @param array &$pps_array Reference to the array of PPS's for the whole OLE + * @param array &$raList Reference to the array of PPS's for the whole OLE * container * @return integer The index for this PPS */ - public function _savePpsSetPnt(&$pps_array) + public static function _savePpsSetPnt(&$raList, $to_save, $depth = 0) { - $pps_array[count($pps_array)] = &$this; - $this->No = count($pps_array) - 1; - $this->PrevPps = 0xFFFFFFFF; - $this->NextPps = 0xFFFFFFFF; - if (count($this->children) > 0) { - $this->DirPps = $this->children[0]->_savePpsSetPnt($pps_array); + if ( !is_array($to_save) || (count($to_save) == 0) ) { + return 0xFFFFFFFF; + } elseif( count($to_save) == 1 ) { + $cnt = count($raList); + // If the first entry, it's the root... Don't clone it! + $raList[$cnt] = ( $depth == 0 ) ? $to_save[0] : clone $to_save[0]; + $raList[$cnt]->No = $cnt; + $raList[$cnt]->PrevPps = 0xFFFFFFFF; + $raList[$cnt]->NextPps = 0xFFFFFFFF; + $raList[$cnt]->DirPps = self::_savePpsSetPnt($raList, @$raList[$cnt]->children, $depth++); } else { - $this->DirPps = 0xFFFFFFFF; + $iPos = floor(count($to_save) / 2); + $aPrev = array_slice($to_save, 0, $iPos); + $aNext = array_slice($to_save, $iPos + 1); + $cnt = count($raList); + // If the first entry, it's the root... Don't clone it! + $raList[$cnt] = ( $depth == 0 ) ? $to_save[$iPos] : clone $to_save[$iPos]; + $raList[$cnt]->No = $cnt; + $raList[$cnt]->PrevPps = self::_savePpsSetPnt($raList, $aPrev, $depth++); + $raList[$cnt]->NextPps = self::_savePpsSetPnt($raList, $aNext, $depth++); + $raList[$cnt]->DirPps = self::_savePpsSetPnt($raList, @$raList[$cnt]->children, $depth++); + } - return $this->No; + return $cnt; } } diff --git a/Classes/PHPExcel/Shared/OLE/PPS/Root.php b/Classes/PHPExcel/Shared/OLE/PPS/Root.php index e736851..d06b14f 100644 --- a/Classes/PHPExcel/Shared/OLE/PPS/Root.php +++ b/Classes/PHPExcel/Shared/OLE/PPS/Root.php @@ -92,7 +92,7 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS } // Make an array of PPS's (for Save) $aList = array(); - $this->_savePpsSetPnt($aList); + PHPExcel_Shared_OLE_PPS::_savePpsSetPnt($aList, array($this)); // calculate values for header list($iSBDcnt, $iBBcnt, $iPPScnt) = $this->_calcSize($aList); //, $rhInfo); // Save Header @@ -204,31 +204,31 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS // Save Header fwrite($FILE, - "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" - . "\x00\x00\x00\x00" - . "\x00\x00\x00\x00" - . "\x00\x00\x00\x00" - . "\x00\x00\x00\x00" - . pack("v", 0x3b) - . pack("v", 0x03) - . pack("v", -2) - . pack("v", 9) - . pack("v", 6) - . pack("v", 0) - . "\x00\x00\x00\x00" - . "\x00\x00\x00\x00" - . pack("V", $iBdCnt) - . pack("V", $iBBcnt+$iSBDcnt) //ROOT START - . pack("V", 0) - . pack("V", 0x1000) - . pack("V", $iSBDcnt ? 0 : -2) //Small Block Depot - . pack("V", $iSBDcnt) + "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" + . "\x00\x00\x00\x00" + . "\x00\x00\x00\x00" + . "\x00\x00\x00\x00" + . "\x00\x00\x00\x00" + . pack("v", 0x3b) + . pack("v", 0x03) + . pack("v", -2) + . pack("v", 9) + . pack("v", 6) + . pack("v", 0) + . "\x00\x00\x00\x00" + . "\x00\x00\x00\x00" + . pack("V", $iBdCnt) + . pack("V", $iBBcnt+$iSBDcnt) //ROOT START + . pack("V", 0) + . pack("V", 0x1000) + . pack("V", $iSBDcnt ? 0 : -2) //Small Block Depot + . pack("V", $iSBDcnt) ); // Extra BDList Start, Count if ($iBdCnt < $i1stBdL) { fwrite($FILE, - pack("V", -2). // Extra BDList Start - pack("V", 0) // Extra BDList Count + pack("V", -2) // Extra BDList Start + . pack("V", 0) // Extra BDList Count ); } else { fwrite($FILE, pack("V", $iAll+$iBdCnt) . pack("V", $iBdExL));