support "showZeros" setting in Excel advanced worksheet options (#1199)
* support "showZeros" setting in Excel advanced worksheet options * add changelog entry * change isShowZeros to getShowZeros
This commit is contained in:
		
							parent
							
								
									43b760501a
								
							
						
					
					
						commit
						55209424b2
					
				@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
 | 
				
			|||||||
### Added
 | 
					### Added
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Implementation of IFNA() logical function
 | 
					- Implementation of IFNA() logical function
 | 
				
			||||||
 | 
					- Support "showZeros" worksheet option to change how Excel shows and handles "null" values returned from a calculation
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Fixed
 | 
					### Fixed
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -2813,7 +2813,7 @@ class Calculation
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        self::$returnArrayAsType = $returnArrayAsType;
 | 
					        self::$returnArrayAsType = $returnArrayAsType;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if ($result === null) {
 | 
					        if ($result === null && $pCell->getWorksheet()->getSheetView()->getShowZeros()) {
 | 
				
			||||||
            return 0;
 | 
					            return 0;
 | 
				
			||||||
        } elseif ((is_float($result)) && ((is_nan($result)) || (is_infinite($result)))) {
 | 
					        } elseif ((is_float($result)) && ((is_nan($result)) || (is_infinite($result)))) {
 | 
				
			||||||
            return Functions::NAN();
 | 
					            return Functions::NAN();
 | 
				
			||||||
 | 
				
			|||||||
@ -24,6 +24,7 @@ class SheetViews extends BaseParserClass
 | 
				
			|||||||
        $this->gridLines();
 | 
					        $this->gridLines();
 | 
				
			||||||
        $this->headers();
 | 
					        $this->headers();
 | 
				
			||||||
        $this->direction();
 | 
					        $this->direction();
 | 
				
			||||||
 | 
					        $this->showZeros();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (isset($this->sheetViewXml->pane)) {
 | 
					        if (isset($this->sheetViewXml->pane)) {
 | 
				
			||||||
            $this->pane();
 | 
					            $this->pane();
 | 
				
			||||||
@ -92,6 +93,15 @@ class SheetViews extends BaseParserClass
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private function showZeros()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        if (isset($this->sheetViewXml['showZeros'])) {
 | 
				
			||||||
 | 
					            $this->worksheet->getSheetView()->setShowZeros(
 | 
				
			||||||
 | 
					                self::boolean((string) $this->sheetViewXml['showZeros'])
 | 
				
			||||||
 | 
					            );
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private function pane()
 | 
					    private function pane()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $xSplit = 0;
 | 
					        $xSplit = 0;
 | 
				
			||||||
 | 
				
			|||||||
@ -35,6 +35,16 @@ class SheetView
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    private $zoomScaleNormal = 100;
 | 
					    private $zoomScaleNormal = 100;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * ShowZeros.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * If true, "null" values from a calculation will be shown as "0". This is the default Excel behaviour and can be changed
 | 
				
			||||||
 | 
					     * with the advanced worksheet option "Show a zero in cells that have zero value"
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @var bool
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private $showZeros = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * View.
 | 
					     * View.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
@ -115,6 +125,24 @@ class SheetView
 | 
				
			|||||||
        return $this;
 | 
					        return $this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Set ShowZeroes setting.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param bool $pValue
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public function setShowZeros($pValue)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $this->showZeros = $pValue;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * @return bool
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public function getShowZeros()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return $this->showZeros;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Get View.
 | 
					     * Get View.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
 | 
				
			|||||||
@ -221,6 +221,11 @@ class Worksheet extends WriterPart
 | 
				
			|||||||
            $objWriter->writeAttribute('zoomScaleNormal', $pSheet->getSheetView()->getZoomScaleNormal());
 | 
					            $objWriter->writeAttribute('zoomScaleNormal', $pSheet->getSheetView()->getZoomScaleNormal());
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Show zeros (Excel also writes this attribute only if set to false)
 | 
				
			||||||
 | 
					        if ($pSheet->getSheetView()->getShowZeros() === false) {
 | 
				
			||||||
 | 
					            $objWriter->writeAttribute('showZeros', 0);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // View Layout Type
 | 
					        // View Layout Type
 | 
				
			||||||
        if ($pSheet->getSheetView()->getView() !== SheetView::SHEETVIEW_NORMAL) {
 | 
					        if ($pSheet->getSheetView()->getView() !== SheetView::SHEETVIEW_NORMAL) {
 | 
				
			||||||
            $objWriter->writeAttribute('view', $pSheet->getSheetView()->getView());
 | 
					            $objWriter->writeAttribute('view', $pSheet->getSheetView()->getView());
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user