Quantcast
Channel: PHPExcel Forum Rss Feed
Viewing all articles
Browse latest Browse all 2707

New Post: Ability to set initial scroll position

$
0
0
The code below should help implement the functionality for the Writer Excel 2007

1 - Edit the PHPExcel_Worksheet class (PHPExcel/Worksheet.php)
  • Add a property class $_topLeftCellView:
/**
    * topLeftCellView
    *
    * @var string
    */
    private $_topLeftCellView = null;
  • Add both setTopLeftCellView and getTopLeftCellView methods:
/**
     * Define the Top Left visible Cell
     *
     * @param string        $pCoord
     */
    public function setTopLeftCellView($pCoord = null){
        if($pCoord=='' or strtoupper($pCoord)=='A1') $pCoord=null;
        $this->_topLeftCellView=$pCoord;
        return $this;
    }
    /**
     * get the Top Left visible Cell
     *
     * @return   string || null
     */
    public function getTopLeftCellView(){
        return $this->_topLeftCellView;
    }
2 - Edit the class PHPExcel_Writer_Excel2007_Worksheet (PHPExcel/Writer/Excel2007/Worksheet.php
  • Search (it's a "tab" between the two params):
$objWriter->writeAttribute('topLeftCell',   $topLeftCell);
  • Replace by:
$objWriter->writeAttribute('topLeftCell',   (is_null($pSheet->getTopLeftCellView())?$topLeftCell:$pSheet->getTopLeftCellView()));
  • Search the end of if corresponding to :
if (($topLeftCell != '') && ($topLeftCell != 'A1')) {
  • Add a 'else' to this test:
}else{
                    //initial visible (top left) cell
                    if(!is_null($pSheet->getTopLeftCellView())){
                        $objWriter->writeAttribute('topLeftCell', $pSheet->getTopLeftCellView());
                    }
                }
If you want the corresponding Reader read the value into an existing file:
1 - Edit the PHPExcel_Reader_Excel2007 class (PHPExcel/Reader/Excel2007.php)
  • Search :
if (isset($xmlSheet->sheetViews->sheetView->pane['topLeftCell'])) {
Comment (or remove) the 'end of if' (only the '}') of this test, comment (or remove) the 'else' (only the 'else{')
Note : Of origin, there is a small mistake here: topLeftCell does not always correspond to xSplit and ySplit, for example when the user has moved the view after a freeze pane.
  • Search :
$docSheet->freezePane( (string)$xmlSheet->sheetViews->sheetView->pane['topLeftCell'] );
  • and replace with :
$docSheet->setTopLeftCellView((string)$xmlSheet->sheetViews->sheetView->pane['topLeftCell'] );

Viewing all articles
Browse latest Browse all 2707


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>