Skip to content
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ and this project adheres to [Semantic Versioning](https://semver.org). Thia is a

### Deprecated

- Nothing yet.
- Worksheet::getHashInt serves no useful purpose. No replacement.
- Spreadsheet::getId serves no useful purpose. No replacement.

### Fixed

- Performance improvement when working with large amounts of cells. [Issue #4607](https://github.com/PHPOffice/PhpSpreadsheet/issues/4607) [PR #4609](https://github.com/PHPOffice/PhpSpreadsheet/pull/4609)
- Minor improvements to Calculation coverage. [PR #4624](https://github.com/PHPOffice/PhpSpreadsheet/pull/4624)
- Conditional formatting in extLst. [Issue #4629](https://github.com/PHPOffice/PhpSpreadsheet/issues/4629) [PR #4633](https://github.com/PHPOffice/PhpSpreadsheet/pull/4633)
- Php8.5 deprecates use of null as array index. [PR #4634](https://github.com/PHPOffice/PhpSpreadsheet/pull/4634)
- For Php8.5, replace one of our two uses of `__wakeup` with `__unserialize`, and eliminate the other. [PR #4639](https://github.com/PHPOffice/PhpSpreadsheet/pull/4639)
- Use prefix _xlfn for BASE function. [Issue #4638](https://github.com/PHPOffice/PhpSpreadsheet/issues/4638) [PR #4641](https://github.com/PHPOffice/PhpSpreadsheet/pull/4641)

## 2025-09-03 - 5.1.0
Expand Down
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/ReferenceHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ private function updateNamedRange(DefinedName $definedName, Worksheet $worksheet
{
$cellAddress = $definedName->getValue();
$asFormula = ($cellAddress[0] === '=');
if ($definedName->getWorksheet() !== null && $definedName->getWorksheet()->getHashInt() === $worksheet->getHashInt()) {
if ($definedName->getWorksheet() === $worksheet) {
/**
* If we delete the entire range that is referenced by a Named Range, MS Excel sets the value to #REF!
* PhpSpreadsheet still only does a basic adjustment, so the Named Range will still reference Cells.
Expand All @@ -1064,7 +1064,7 @@ private function updateNamedRange(DefinedName $definedName, Worksheet $worksheet

private function updateNamedFormula(DefinedName $definedName, Worksheet $worksheet, string $beforeCellAddress, int $numberOfColumns, int $numberOfRows): void
{
if ($definedName->getWorksheet() !== null && $definedName->getWorksheet()->getHashInt() === $worksheet->getHashInt()) {
if ($definedName->getWorksheet() === $worksheet) {
/**
* If we delete the entire range that is referenced by a Named Formula, MS Excel sets the value to #REF!
* PhpSpreadsheet still only does a basic adjustment, so the Named Formula will still reference Cells.
Expand Down
7 changes: 6 additions & 1 deletion src/PhpSpreadsheet/Shared/XMLWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public function __construct(int $temporaryStorage = self::STORAGE_MEMORY, ?strin
if (empty($this->tempFileName) || $this->openUri($this->tempFileName) === false) {
// Fallback to memory...
$this->openMemory();
if ($this->tempFileName != '') {
@unlink($this->tempFileName);
}
$this->tempFileName = '';
}
}

Expand All @@ -60,7 +64,8 @@ public function __destruct()
}
}

public function __wakeup(): void
/** @param mixed[] $data */
public function __unserialize(array $data): void
{
$this->tempFileName = '';

Expand Down
7 changes: 5 additions & 2 deletions src/PhpSpreadsheet/Spreadsheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -735,9 +735,8 @@ public function getSheetByNameOrThrow(string $worksheetName): Worksheet
*/
public function getIndex(Worksheet $worksheet, bool $noThrow = false): int
{
$wsHash = $worksheet->getHashInt();
foreach ($this->workSheetCollection as $key => $value) {
if ($value->getHashInt() === $wsHash) {
if ($value === $worksheet) {
return $key;
}
}
Expand Down Expand Up @@ -1468,6 +1467,10 @@ public function garbageCollect(): void

/**
* Return the unique ID value assigned to this spreadsheet workbook.
*
* @deprecated 5.2.0 Serves no useful purpose. No replacement.
*
* @codeCoverageIgnore
*/
public function getID(): string
{
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Worksheet/BaseDrawing.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ public function getHashCode(): string
return md5(
$this->name
. $this->description
. (($this->worksheet === null) ? '' : (string) $this->worksheet->getHashInt())
. (($this->worksheet === null) ? '' : (string) spl_object_id($this->worksheet))
. $this->coordinates
. $this->offsetX
. $this->offsetY
Expand Down
27 changes: 8 additions & 19 deletions src/PhpSpreadsheet/Worksheet/Worksheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,6 @@ class Worksheet
*/
private ?Color $tabColor = null;

/**
* Hash.
*/
private int $hash;

/**
* CodeName.
*/
Expand All @@ -323,7 +318,6 @@ public function __construct(?Spreadsheet $parent = null, string $title = 'Worksh
{
// Set parent and title
$this->parent = $parent;
$this->hash = spl_object_id($this);
$this->setTitle($title, false);
// setTitle can change $pTitle
$this->setCodeName($this->getTitle());
Expand Down Expand Up @@ -380,11 +374,6 @@ public function __destruct()
unset($this->rowDimensions, $this->columnDimensions, $this->tableCollection, $this->drawingCollection, $this->chartCollection, $this->autoFilter);
}

public function __wakeup(): void
{
$this->hash = spl_object_id($this);
}

/**
* Return the cell collection.
*/
Expand Down Expand Up @@ -3212,7 +3201,7 @@ private function validateNamedRange(string $definedName, bool $returnNullIfInval

if ($namedRange->getLocalOnly()) {
$worksheet = $namedRange->getWorksheet();
if ($worksheet === null || $this->hash !== $worksheet->getHashInt()) {
if ($worksheet === null || $this !== $worksheet) {
if ($returnNullIfInvalid) {
return null;
}
Expand Down Expand Up @@ -3344,21 +3333,22 @@ public function garbageCollect(): static
}

// Cache values
if ($highestColumn < 1) {
$this->cachedHighestColumn = 1;
} else {
$this->cachedHighestColumn = $highestColumn;
}
$this->cachedHighestColumn = max(1, $highestColumn);
/** @var int $highestRow */
$this->cachedHighestRow = $highestRow;

// Return
return $this;
}

/**
* @deprecated 5.2.0 Serves no useful purpose. No replacement.
*
* @codeCoverageIgnore
*/
public function getHashInt(): int
{
return $this->hash;
return spl_object_id($this);
}

/**
Expand Down Expand Up @@ -3745,7 +3735,6 @@ public function __clone()
}
}
}
$this->hash = spl_object_id($this);
}

/**
Expand Down
1 change: 0 additions & 1 deletion tests/PhpSpreadsheetTests/Reader/Xml/XmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public function testLoadCorruptedFile(): void

$xmlReader = new Xml();
$spreadsheet = @$xmlReader->load('tests/data/Reader/Xml/CorruptedXmlFile.xml');
self::assertNotSame('', $spreadsheet->getID());
}

public function testListWorksheetNamesCorruptedFile(): void
Expand Down
13 changes: 13 additions & 0 deletions tests/PhpSpreadsheetTests/Shared/XMLWriterNoUri.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace PhpOffice\PhpSpreadsheetTests\Shared;

class XMLWriterNoUri extends \PhpOffice\PhpSpreadsheet\Shared\XMLWriter
{
public function openUri(string $uri): bool
{
return false;
}
}
24 changes: 24 additions & 0 deletions tests/PhpSpreadsheetTests/Shared/XmlWriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,28 @@ public function testDiskCache(): void
$expected .= '</root>' . $indentnl;
self::assertSame($expected, $objWriter->getData());
}

public function testFallbackToMemory(): void
{
XMLWriter::$debugEnabled = false;
$indent = '';
$indentnl = '';
$objWriter = new XMLWriterNoUri(XMLWriter::STORAGE_DISK);
$objWriter->startDocument('1.0', 'UTF-8', 'yes');
$expected = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' . "\n";
$objWriter->startElement('root');
$expected .= '<root>' . $indentnl;
$objWriter->startElement('node');
$expected .= $indent . '<node>';
$objWriter->writeRawData('xyz');
$expected .= 'xyz';
$objWriter->writeRawData(null);
$objWriter->writeRawData(['12', '34', '5']);
$expected .= "12\n34\n5";
$objWriter->endElement(); // node
$expected .= '</node>' . $indentnl;
$objWriter->endElement(); // root
$expected .= '</root>' . $indentnl;
self::assertSame($expected, $objWriter->getData());
}
}
4 changes: 2 additions & 2 deletions tests/PhpSpreadsheetTests/Worksheet/CloneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function testSerialize1(): void
$newSheet = unserialize($serialized);
self::assertInstanceOf(Worksheet::class, $newSheet);
self::assertSame(10, $newSheet->getCell('A1')->getValue());
self::assertNotEquals($newSheet->getHashInt(), $sheet1->getHashInt());
self::assertNotSame($newSheet, $sheet1);
self::assertNotNull($newSheet->getParent());
self::assertNotSame($newSheet->getParent(), $sheet1->getParent());
$newSheet->getParent()->disconnectWorksheets();
Expand All @@ -66,6 +66,6 @@ public function testSerialize2(): void
$newSheet = unserialize($serialized);
self::assertInstanceOf(Worksheet::class, $newSheet);
self::assertSame(10, $newSheet->getCell('A1')->getValue());
self::assertNotEquals($newSheet->getHashInt(), $sheet1->getHashInt());
self::assertNotSame($newSheet, $sheet1);
}
}