Skip to content
This repository has been archived by the owner on Jan 2, 2019. It is now read-only.

Fill SheetView IO in Excel5 #85

Merged
merged 2 commits into from
Nov 24, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions Classes/PHPExcel/Reader/Excel5.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class PHPExcel_Reader_Excel5 extends PHPExcel_Reader_Abstract implements PHPExce
const XLS_Type_RANGEPROTECTION = 0x0868;
const XLS_Type_SHEETLAYOUT = 0x0862;
const XLS_Type_XFEXT = 0x087d;
const XLS_Type_PAGELAYOUTVIEW = 0x088b;
const XLS_Type_UNKNOWN = 0xffff;


Expand Down Expand Up @@ -784,6 +785,7 @@ public function load($pFilename)
case self::XLS_Type_MSODRAWING: $this->_readMsoDrawing(); break;
case self::XLS_Type_OBJ: $this->_readObj(); break;
case self::XLS_Type_WINDOW2: $this->_readWindow2(); break;
case self::XLS_Type_PAGELAYOUTVIEW: $this->_readPageLayoutView(); break;
case self::XLS_Type_SCL: $this->_readScl(); break;
case self::XLS_Type_PANE: $this->_readPane(); break;
case self::XLS_Type_SELECTION: $this->_readSelection(); break;
Expand Down Expand Up @@ -3993,6 +3995,22 @@ private function _readWindow2()
// offset: 0; size: 2; option flags
$options = self::_GetInt2d($recordData, 0);

// offset: 2; size: 2; index to first visible row
$firstVisibleRow = self::_GetInt2d($recordData, 2);

// offset: 4; size: 2; index to first visible colum
$firstVisibleColumn = self::_GetInt2d($recordData, 4);
if ($this->_version === self::XLS_BIFF8) {
// offset: 8; size: 2; not used
// offset: 10; size: 2; cached magnification factor in page break preview (in percent); 0 = Default (60%)
// offset: 12; size: 2; cached magnification factor in normal view (in percent); 0 = Default (100%)
// offset: 14; size: 4; not used
$zoomscaleInPageBreakPreview = self::_GetInt2d($recordData, 10);
if ($zoomscaleInPageBreakPreview === 0) $zoomscaleInPageBreakPreview = 60;
$zoomscaleInNormalView = self::_GetInt2d($recordData, 12);
if ($zoomscaleInNormalView === 0) $zoomscaleInNormalView = 100;
}

// bit: 1; mask: 0x0002; 0 = do not show gridlines, 1 = show gridlines
$showGridlines = (bool) ((0x0002 & $options) >> 1);
$this->_phpSheet->setShowGridlines($showGridlines);
Expand All @@ -4012,8 +4030,62 @@ private function _readWindow2()
if ($isActive) {
$this->_phpExcel->setActiveSheetIndex($this->_phpExcel->getIndex($this->_phpSheet));
}

// bit: 11; mask: 0x0800; 0 = normal view, 1 = page break view
$isPageBreakPreview = (bool) ((0x0800 & $options) >> 11);

//FIXME: set $firstVisibleRow and $firstVisibleColumn

if ($this->_phpSheet->getSheetView()->getView() !== PHPExcel_Worksheet_SheetView::SHEETVIEW_PAGE_LAYOUT) {
//NOTE: this setting is inferior to page layout view(Excel2007-)
$view = $isPageBreakPreview? PHPExcel_Worksheet_SheetView::SHEETVIEW_PAGE_BREAK_PREVIEW :
PHPExcel_Worksheet_SheetView::SHEETVIEW_NORMAL;
$this->_phpSheet->getSheetView()->setView($view);
if ($this->_version === self::XLS_BIFF8) {
$zoomScale = $isPageBreakPreview? $zoomscaleInPageBreakPreview : $zoomscaleInNormalView;
$this->_phpSheet->getSheetView()->setZoomScale($zoomScale);
$this->_phpSheet->getSheetView()->setZoomScaleNormal($zoomscaleInNormalView);
}
}
}

/**
* Read PLV Record(Created by Excel2007 or upper)
*/
private function _readPageLayoutView(){
$length = self::_GetInt2d($this->_data, $this->_pos + 2);
$recordData = substr($this->_data, $this->_pos + 4, $length);

// move stream pointer to next record
$this->_pos += 4 + $length;

//var_dump(unpack("vrt/vgrbitFrt/V2reserved/vwScalePLV/vgrbit", $recordData));

// offset: 0; size: 2; rt
//->ignore
$rt = self::_GetInt2d($recordData, 0);
// offset: 2; size: 2; grbitfr
//->ignore
$grbitFrt = self::_GetInt2d($recordData, 2);
// offset: 4; size: 8; reserved
//->ignore

// offset: 12; size 2; zoom scale
$wScalePLV = self::_GetInt2d($recordData, 12);
// offset: 14; size 2; grbit
$grbit = self::_GetInt2d($recordData, 14);

// decomprise grbit
$fPageLayoutView = $grbit & 0x01;
$fRulerVisible = ($grbit >> 1) & 0x01; //no support
$fWhitespaceHidden = ($grbit >> 3) & 0x01; //no support

if ($fPageLayoutView === 1) {
$this->_phpSheet->getSheetView()->setView(PHPExcel_Worksheet_SheetView::SHEETVIEW_PAGE_LAYOUT);
$this->_phpSheet->getSheetView()->setZoomScale($wScalePLV); //set by Excel2007 only if SHEETVIEW_PAGE_LAYOUT
}
//otherwise, we cannot know whether SHEETVIEW_PAGE_LAYOUT or SHEETVIEW_PAGE_BREAK_PREVIEW.
}

/**
* Read SCL record
Expand Down
9 changes: 6 additions & 3 deletions Classes/PHPExcel/Writer/Excel5/Worksheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,7 @@ private function _writeWindow2()
// no support in PHPExcel for selected sheet, therefore sheet is only selected if it is the active sheet
$fSelected = ($this->_phpSheet === $this->_phpSheet->getParent()->getActiveSheet()) ? 1 : 0;
$fPaged = 1; // 2
$fPageBreakPreview = $this->_phpSheet->getSheetView()->getView() === PHPExcel_Worksheet_SheetView::SHEETVIEW_PAGE_BREAK_PREVIEW;

$grbit = $fDspFmla;
$grbit |= $fDspGrid << 1;
Expand All @@ -1290,14 +1291,16 @@ private function _writeWindow2()
$grbit |= $fFrozenNoSplit << 8;
$grbit |= $fSelected << 9;
$grbit |= $fPaged << 10;
$grbit |= $fPageBreakPreview << 11;

$header = pack("vv", $record, $length);
$data = pack("vvv", $grbit, $rwTop, $colLeft);

// FIXME !!!
$rgbHdr = 0x0040; // Row/column heading and gridline color index
$zoom_factor_page_break = 0x0000;
$zoom_factor_normal = 0x0000;
$zoom_factor_page_break = ($fPageBreakPreview? $this->_phpSheet->getSheetView()->getZoomScale() : 0x0000);
$zoom_factor_normal = $this->_phpSheet->getSheetView()->getZoomScaleNormal();

$data .= pack("vvvvV", $rgbHdr, 0x0000, $zoom_factor_page_break, $zoom_factor_normal, 0x00000000);

$this->_append($header.$data);
Expand Down Expand Up @@ -2982,4 +2985,4 @@ private function _writePageLayoutView(){
$data = pack("vvVVvv", $rt, $grbitFrt, 0x00000000, 0x00000000, $wScalvePLV, $grbit);
$this->_append($header . $data);
}
}
}