Merge remote-tracking branch 'origin/master'

This commit is contained in:
MarkBaker 2019-10-28 21:53:40 +01:00
commit ab6e87fb1c
6 changed files with 51 additions and 2 deletions

View File

@ -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

View File

@ -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();

View File

@ -273,7 +273,12 @@ class TextData
$decimals = 0; $decimals = 0;
} }
if (!$no_commas) { if (!$no_commas) {
$valueResult = number_format($valueResult, $decimals); $valueResult = number_format(
$valueResult,
$decimals,
StringHelper::getDecimalSeparator(),
StringHelper::getThousandsSeparator()
);
} }
return (string) $valueResult; return (string) $valueResult;

View File

@ -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;

View File

@ -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.
* *

View File

@ -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());