Skip to content

Commit 15fb1b5

Browse files
authored
Merge branch 'master' into issue4049
2 parents 24e6f4d + 626b08f commit 15fb1b5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+808
-118
lines changed

CHANGELOG.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ and this project adheres to [Semantic Versioning](https://semver.org).
99

1010
### Added
1111

12-
- Nothing
12+
- Xlsx Reader Optionally Ignore Rows With No Cells. [Issue #3982](https://github.com/PHPOffice/PhpSpreadsheet/issues/3982) [PR #4035](https://github.com/PHPOffice/PhpSpreadsheet/pull/4035)
1313

1414
### Changed
1515

1616
- Nothing
1717

1818
### Deprecated
1919

20-
- Nothing
20+
- Writer\Xls\Style\ColorMap is no longer needed.
2121

2222
### Moved
2323

@@ -28,8 +28,10 @@ and this project adheres to [Semantic Versioning](https://semver.org).
2828
- Incorrect Reader CSV with BOM. [Issue #4028](https://github.com/PHPOffice/PhpSpreadsheet/issues/4028) [PR #4029](https://github.com/PHPOffice/PhpSpreadsheet/pull/4029)
2929
- POWER Null/Bool Args. [PR #4031](https://github.com/PHPOffice/PhpSpreadsheet/pull/4031)
3030
- Do Not Output Alignment and Protection for Conditional Format. [Issue #4025](https://github.com/PHPOffice/PhpSpreadsheet/issues/4025) [PR #4027](https://github.com/PHPOffice/PhpSpreadsheet/pull/4027)
31-
- Xls Conditional Format Improvements. [PR #4030](https://github.com/PHPOffice/PhpSpreadsheet/pull/4030)
3231
- Conditional Color Scale Improvements. [Issue #4049](https://github.com/PHPOffice/PhpSpreadsheet/issues/4049) [PR #4050](https://github.com/PHPOffice/PhpSpreadsheet/pull/4050)
32+
- Mpdf and Tcpdf Borders on Merged Cells. [Issue #3557](https://github.com/PHPOffice/PhpSpreadsheet/issues/3557) [PR #4047](https://github.com/PHPOffice/PhpSpreadsheet/pull/4047)
33+
- Xls Conditional Format Improvements. [PR #4030](https://github.com/PHPOffice/PhpSpreadsheet/pull/4030) [PR #4033](https://github.com/PHPOffice/PhpSpreadsheet/pull/4033)
34+
- Csv Reader allow use of html mimetype. [Issue #4036](https://github.com/PHPOffice/PhpSpreadsheet/issues/4036) [PR #4049](https://github.com/PHPOffice/PhpSpreadsheet/pull/4040)
3335

3436
## 2024-05-11 - 2.1.0
3537

samples/Financial2/DISC.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
require __DIR__ . '/../Header.php';
77

8-
$helper->log('Returns the the Discount Rate for a security.');
8+
$helper->log('Returns the Discount Rate for a security.');
99

1010
// Create new PhpSpreadsheet object
1111
$spreadsheet = new Spreadsheet();

src/PhpSpreadsheet/Collection/Cells.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public function cloneCellCollection(Worksheet $worksheet): static
288288
$newCollection->index[$key] = $value;
289289
$stored = $newCollection->cache->set(
290290
$newCollection->cachePrefix . $key,
291-
clone $this->cache->get($this->cachePrefix . $key)
291+
clone $this->getCache($key)
292292
);
293293
if ($stored === false) {
294294
$this->destructIfNeeded($newCollection, 'Failed to copy cells in cache');
@@ -410,11 +410,7 @@ public function get(string $cellCoordinate): ?Cell
410410
return null;
411411
}
412412

413-
// Check if the entry that has been requested actually exists in the cache
414-
$cell = $this->cache->get($this->cachePrefix . $cellCoordinate);
415-
if ($cell === null) {
416-
throw new PhpSpreadsheetException("Cell entry {$cellCoordinate} no longer exists in cache. This probably means that the cache was cleared by someone else.");
417-
}
413+
$cell = $this->getcache($cellCoordinate);
418414

419415
// Set current entry to the requested entry
420416
$this->currentCoordinate = $cellCoordinate;
@@ -466,4 +462,14 @@ private function getAllCacheKeys(): iterable
466462
yield $this->cachePrefix . $coordinate;
467463
}
468464
}
465+
466+
private function getCache(string $cellCoordinate): Cell
467+
{
468+
$cell = $this->cache->get($this->cachePrefix . $cellCoordinate);
469+
if (!($cell instanceof Cell)) {
470+
throw new PhpSpreadsheetException("Cell entry {$cellCoordinate} no longer exists in cache. This probably means that the cache was cleared by someone else.");
471+
}
472+
473+
return $cell;
474+
}
469475
}

src/PhpSpreadsheet/Helper/Html.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PhpOffice\PhpSpreadsheet\Helper;
44

5+
use DOMAttr;
56
use DOMDocument;
67
use DOMElement;
78
use DOMNode;
@@ -708,6 +709,7 @@ protected function startFontTag(DOMElement $tag): void
708709
{
709710
$attrs = $tag->attributes;
710711
if ($attrs !== null) {
712+
/** @var DOMAttr $attribute */
711713
foreach ($attrs as $attribute) {
712714
$attributeName = strtolower($attribute->name);
713715
$attributeName = preg_replace('/^html:/', '', $attributeName) ?? $attributeName; // in case from Xml spreadsheet

src/PhpSpreadsheet/Helper/Sample.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,9 @@ public function getSamples(): array
8181
$regex = new RegexIterator($iterator, '/^.+\.php$/', RecursiveRegexIterator::GET_MATCH);
8282

8383
$files = [];
84+
/** @var string[] $file */
8485
foreach ($regex as $file) {
8586
$file = str_replace(str_replace('\\', '/', $baseDir) . '/', '', str_replace('\\', '/', $file[0]));
86-
if (is_array($file)) {
87-
// @codeCoverageIgnoreStart
88-
throw new RuntimeException('str_replace returned array');
89-
// @codeCoverageIgnoreEnd
90-
}
9187
$info = pathinfo($file);
9288
$category = str_replace('_', ' ', $info['dirname'] ?? '');
9389
$name = str_replace('_', ' ', (string) preg_replace('/(|\.php)/', '', $info['filename']));
@@ -254,10 +250,10 @@ public function logCalculationResult(
254250
?string $descriptionCell = null
255251
): void {
256252
if ($descriptionCell !== null) {
257-
$this->log($worksheet->getCell($descriptionCell)->getValue());
253+
$this->log($worksheet->getCell($descriptionCell)->getValueString());
258254
}
259-
$this->log($worksheet->getCell($formulaCell)->getValue());
260-
$this->log(sprintf('%s() Result is ', $functionName) . $worksheet->getCell($formulaCell)->getCalculatedValue());
255+
$this->log($worksheet->getCell($formulaCell)->getValueString());
256+
$this->log(sprintf('%s() Result is ', $functionName) . $worksheet->getCell($formulaCell)->getCalculatedValueString());
261257
}
262258

263259
/**

src/PhpSpreadsheet/Reader/BaseReader.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ abstract class BaseReader implements IReader
3939
*/
4040
protected ?array $loadSheetsOnly = null;
4141

42+
/**
43+
* Ignore rows with no cells?
44+
* Identifies whether the Reader should ignore rows with no cells.
45+
* Currently implemented only for Xlsx.
46+
*/
47+
protected bool $ignoreRowsWithNoCells = false;
48+
4249
/**
4350
* IReadFilter instance.
4451
*/
@@ -78,6 +85,18 @@ public function setReadEmptyCells(bool $readEmptyCells): self
7885
return $this;
7986
}
8087

88+
public function getIgnoreRowsWithNoCells(): bool
89+
{
90+
return $this->ignoreRowsWithNoCells;
91+
}
92+
93+
public function setIgnoreRowsWithNoCells(bool $ignoreRowsWithNoCells): self
94+
{
95+
$this->ignoreRowsWithNoCells = $ignoreRowsWithNoCells;
96+
97+
return $this;
98+
}
99+
81100
public function getIncludeCharts(): bool
82101
{
83102
return $this->includeCharts;
@@ -150,6 +169,9 @@ protected function processFlags(int $flags): void
150169
if (((bool) ($flags & self::SKIP_EMPTY_CELLS) || (bool) ($flags & self::IGNORE_EMPTY_CELLS)) === true) {
151170
$this->setReadEmptyCells(false);
152171
}
172+
if (((bool) ($flags & self::IGNORE_ROWS_WITH_NO_CELLS)) === true) {
173+
$this->setIgnoreRowsWithNoCells(true);
174+
}
153175
}
154176

155177
protected function loadSpreadsheetFromFile(string $filename): Spreadsheet

src/PhpSpreadsheet/Reader/Csv.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ public function canRead(string $filename): bool
566566
'text/csv',
567567
'text/plain',
568568
'inode/x-empty',
569+
'text/html',
569570
];
570571

571572
return in_array($type, $supportedTypes, true);

src/PhpSpreadsheet/Reader/Html.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PhpOffice\PhpSpreadsheet\Reader;
44

5+
use DOMAttr;
56
use DOMDocument;
67
use DOMElement;
78
use DOMNode;
@@ -289,6 +290,7 @@ protected function flushCell(Worksheet $sheet, string $column, int|string $row,
289290
private function processDomElementBody(Worksheet $sheet, int &$row, string &$column, string &$cellContent, DOMElement $child): void
290291
{
291292
$attributeArray = [];
293+
/** @var DOMAttr $attribute */
292294
foreach ($child->attributes as $attribute) {
293295
$attributeArray[$attribute->name] = $attribute->value;
294296
}

src/PhpSpreadsheet/Reader/IReader.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ interface IReader
1313
public const SKIP_EMPTY_CELLS = 4;
1414
public const IGNORE_EMPTY_CELLS = 4;
1515

16+
public const IGNORE_ROWS_WITH_NO_CELLS = 8;
17+
1618
public function __construct();
1719

1820
/**

src/PhpSpreadsheet/Reader/Slk.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ private function processCRecord(array $rowData, Spreadsheet &$spreadsheet, strin
268268
if ($sharedFormula === true && $sharedRow >= 0 && $sharedColumn >= 0) {
269269
$thisCoordinate = Coordinate::stringFromColumnIndex((int) $column) . $row;
270270
$sharedCoordinate = Coordinate::stringFromColumnIndex($sharedColumn) . $sharedRow;
271+
/** @var string */
271272
$formula = $spreadsheet->getActiveSheet()->getCell($sharedCoordinate)->getValue();
272273
$spreadsheet->getActiveSheet()->getCell($thisCoordinate)->setValue($formula);
273274
$referenceHelper = ReferenceHelper::getInstance();
@@ -281,6 +282,7 @@ private function processCRecord(array $rowData, Spreadsheet &$spreadsheet, strin
281282
return;
282283
}
283284
$columnLetter = Coordinate::stringFromColumnIndex((int) $column);
285+
/** @var string */
284286
$cellData = Calculation::unwrapResult($cellData);
285287

286288
// Set cell value

0 commit comments

Comments
 (0)