Skip to content

Commit

Permalink
Merge branch 'master' into issue3654
Browse files Browse the repository at this point in the history
  • Loading branch information
oleibman committed Aug 22, 2023
2 parents 6d42dde + dcf7415 commit 145c9b1
Show file tree
Hide file tree
Showing 27 changed files with 659 additions and 154 deletions.
35 changes: 18 additions & 17 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions src/PhpSpreadsheet/Calculation/Calculation.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\DefinedName;
use PhpOffice\PhpSpreadsheet\NamedRange;
use PhpOffice\PhpSpreadsheet\ReferenceHelper;
use PhpOffice\PhpSpreadsheet\Shared;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
Expand Down Expand Up @@ -5176,6 +5177,26 @@ private function processTokenStack($tokens, $cellID = null, ?Cell $cell = null)

$this->debugLog->writeDebugLog('Evaluating Defined Name %s', $definedName);
$namedRange = DefinedName::resolveName($definedName, $pCellWorksheet);
// If not Defined Name, try as Table.
if ($namedRange === null && $this->spreadsheet !== null) {
$table = $this->spreadsheet->getTableByName($definedName);
if ($table !== null) {
$tableRange = Coordinate::getRangeBoundaries($table->getRange());
if ($table->getShowHeaderRow()) {
++$tableRange[0][1];
}
if ($table->getShowTotalsRow()) {
--$tableRange[1][1];
}
$tableRangeString =
'$' . $tableRange[0][0]
. '$' . $tableRange[0][1]
. ':'
. '$' . $tableRange[1][0]
. '$' . $tableRange[1][1];
$namedRange = new NamedRange($definedName, $table->getWorksheet(), $tableRangeString);
}
}
if ($namedRange === null) {
return $this->raiseFormulaError("undefined name '$definedName'");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,13 @@ public function parse(Cell $cell): string
{
$this->getTableStructure($cell);
$cellRange = ($this->isRowReference()) ? $this->getRowReference($cell) : $this->getColumnReference();
$sheetName = '';
$worksheet = $this->table->getWorksheet();
if ($worksheet !== null && $worksheet !== $cell->getWorksheet()) {
$sheetName = "'" . $worksheet->getTitle() . "'!";
}

return $cellRange;
return $sheetName . $cellRange;
}

private function isRowReference(): bool
Expand Down Expand Up @@ -115,7 +120,12 @@ private function getTableStructure(Cell $cell): void
$this->totalsRow = ($this->table->getShowTotalsRow()) ? (int) $tableRange[1][1] : null;
$this->lastDataRow = ($this->table->getShowTotalsRow()) ? (int) $tableRange[1][1] - 1 : $tableRange[1][1];

$this->columns = $this->getColumns($cell, $tableRange);
$cellParam = $cell;
$worksheet = $this->table->getWorksheet();
if ($worksheet !== null && $worksheet !== $cell->getWorksheet()) {
$cellParam = $worksheet->getCell('A1');
}
$this->columns = $this->getColumns($cellParam, $tableRange);
}

/**
Expand Down Expand Up @@ -146,6 +156,13 @@ private function getTableByName(Cell $cell): Table
{
$table = $cell->getWorksheet()->getTableByName($this->tableName);

if ($table === null) {
$spreadsheet = $cell->getWorksheet()->getParent();
if ($spreadsheet !== null) {
$table = $spreadsheet->getTableByName($this->tableName);
}
}

if ($table === null) {
throw new Exception("Table {$this->tableName} for Structured Reference cannot be located");
}
Expand Down Expand Up @@ -324,7 +341,7 @@ private function getColumnsForColumnReference(string $reference, int $startRow,
{
$columnsSelected = false;
foreach ($this->columns as $columnId => $columnName) {
$columnName = str_replace("\u{a0}", ' ', $columnName);
$columnName = str_replace("\u{a0}", ' ', $columnName ?? '');
$cellFrom = "{$columnId}{$startRow}";
$cellTo = "{$columnId}{$endRow}";
$cellReference = ($cellFrom === $cellTo) ? $cellFrom : "{$cellFrom}:{$cellTo}";
Expand All @@ -341,4 +358,9 @@ private function getColumnsForColumnReference(string $reference, int $startRow,

return $reference;
}

public function __toString(): string
{
return $this->value;
}
}
9 changes: 3 additions & 6 deletions src/PhpSpreadsheet/Calculation/MathTrig/Sum.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Sum
*
* @param mixed ...$args Data values
*
* @return float|string
* @return float|int|string
*/
public static function sumIgnoringStrings(...$args)
{
Expand Down Expand Up @@ -47,7 +47,7 @@ public static function sumIgnoringStrings(...$args)
*
* @param mixed ...$args Data values
*
* @return float|string
* @return float|int|string
*/
public static function sumErroringStrings(...$args)
{
Expand All @@ -56,10 +56,7 @@ public static function sumErroringStrings(...$args)
$aArgs = Functions::flattenArrayIndexed($args);
foreach ($aArgs as $k => $arg) {
// Is it a numeric value?
if (is_numeric($arg) || empty($arg)) {
if (is_string($arg)) {
$arg = (int) $arg;
}
if (is_numeric($arg)) {
$returnValue += $arg;
} elseif (is_bool($arg)) {
$returnValue += (int) $arg;
Expand Down
17 changes: 10 additions & 7 deletions src/PhpSpreadsheet/Reader/Ods.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,11 @@ public function loadIntoExisting($filename, Spreadsheet $spreadsheet)
Settings::getLibXmlLoaderOptions()
);

$officeNs = $dom->lookupNamespaceUri('office');
$tableNs = $dom->lookupNamespaceUri('table');
$textNs = $dom->lookupNamespaceUri('text');
$xlinkNs = $dom->lookupNamespaceUri('xlink');
$styleNs = $dom->lookupNamespaceUri('style');
$officeNs = (string) $dom->lookupNamespaceUri('office');
$tableNs = (string) $dom->lookupNamespaceUri('table');
$textNs = (string) $dom->lookupNamespaceUri('text');
$xlinkNs = (string) $dom->lookupNamespaceUri('xlink');
$styleNs = (string) $dom->lookupNamespaceUri('style');

$pageSettings->readStyleCrossReferences($dom);

Expand Down Expand Up @@ -624,6 +624,9 @@ public function loadIntoExisting($filename, Spreadsheet $spreadsheet)
}

if ($hyperlink !== null) {
if ($hyperlink[0] === '#') {
$hyperlink = 'sheet://' . substr($hyperlink, 1);
}
$cell->getHyperlink()
->setUrl($hyperlink);
}
Expand Down Expand Up @@ -668,9 +671,9 @@ private function processSettings(ZipArchive $zip, Spreadsheet $spreadsheet): voi
Settings::getLibXmlLoaderOptions()
);
//$xlinkNs = $dom->lookupNamespaceUri('xlink');
$configNs = $dom->lookupNamespaceUri('config');
$configNs = (string) $dom->lookupNamespaceUri('config');
//$oooNs = $dom->lookupNamespaceUri('ooo');
$officeNs = $dom->lookupNamespaceUri('office');
$officeNs = (string) $dom->lookupNamespaceUri('office');
$settings = $dom->getElementsByTagNameNS($officeNs, 'settings')
->item(0);
if ($settings !== null) {
Expand Down
16 changes: 8 additions & 8 deletions src/PhpSpreadsheet/Reader/Ods/PageSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ class PageSettings
/**
* @var string
*/
private $officeNs;
private $officeNs = '';

/**
* @var string
*/
private $stylesNs;
private $stylesNs = '';

/**
* @var string
*/
private $stylesFo;
private $stylesFo = '';

/**
* @var string
*/
private $tableNs;
private $tableNs = '';

/**
* @var string[]
Expand Down Expand Up @@ -55,10 +55,10 @@ public function __construct(DOMDocument $styleDom)

private function setDomNameSpaces(DOMDocument $styleDom): void
{
$this->officeNs = $styleDom->lookupNamespaceUri('office');
$this->stylesNs = $styleDom->lookupNamespaceUri('style');
$this->stylesFo = $styleDom->lookupNamespaceUri('fo');
$this->tableNs = $styleDom->lookupNamespaceUri('table');
$this->officeNs = (string) $styleDom->lookupNamespaceUri('office');
$this->stylesNs = (string) $styleDom->lookupNamespaceUri('style');
$this->stylesFo = (string) $styleDom->lookupNamespaceUri('fo');
$this->tableNs = (string) $styleDom->lookupNamespaceUri('table');
}

private function readPageSettingStyles(DOMDocument $styleDom): void
Expand Down
9 changes: 8 additions & 1 deletion src/PhpSpreadsheet/Reader/Ods/Properties.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,14 @@ private function setMetaProperties(

break;
case 'user-defined':
$this->setUserDefinedProperty($propertyValueAttributes, $propertyValue, $docProps);
$name2 = (string) ($propertyValueAttributes['name'] ?? '');
if ($name2 === 'Company') {
$docProps->setCompany($propertyValue);
} elseif ($name2 === 'category') {
$docProps->setCategory($propertyValue);
} else {
$this->setUserDefinedProperty($propertyValueAttributes, $propertyValue, $docProps);
}

break;
}
Expand Down
Loading

0 comments on commit 145c9b1

Please sign in to comment.