Skip to content

Commit d38b5cd

Browse files
authored
Merge branch 'master' into odspage
2 parents e2ec705 + b03e10b commit d38b5cd

32 files changed

+746
-139
lines changed

.gitattributes

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33
/.gitattributes export-ignore
44
/.github export-ignore
55
/.gitignore export-ignore
6-
/.php_cs.dist export-ignore
6+
/.php-cs-fixer.dist.php export-ignore
7+
/.phpcs.xml.dist export-ignore
8+
/.readthedocs.yaml export-ignore
79
/.scrutinizer.yml export-ignore
810
/CHANGELOG.PHPExcel.md export-ignore
911
/bin export-ignore
1012
/composer.lock export-ignore
1113
/docs export-ignore
1214
/infra export-ignore
1315
/mkdocs.yml export-ignore
16+
/phpstan-baseline.neon export-ignore
17+
/phpstan.neon.dist export-ignore
1418
/phpunit.xml.dist export-ignore
1519
/samples export-ignore
1620
/tests export-ignore

CHANGELOG.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,29 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com)
66
and this project adheres to [Semantic Versioning](https://semver.org).
77

8-
## TBD - 3.6.0
8+
## TBD - 3.7.0
9+
10+
### Added
11+
12+
- Nothing yet.
13+
14+
### Changed
15+
16+
- Nothing yet.
17+
18+
### Moved
19+
20+
- Nothing yet.
21+
22+
### Deprecated
23+
24+
- Drawing::setIsUrl is unneeded. The property is set when setPath determines whether path is a url.
25+
26+
### Fixed
27+
28+
- More context options may be needed for http(s) image. [Php issue 17121](https://github.com/php/php-src/issues/17121) [PR #4276](https://github.com/PHPOffice/PhpSpreadsheet/pull/4276)
29+
30+
## 2024-12-08 - 3.6.0
931

1032
### Added
1133

@@ -25,9 +47,13 @@ and this project adheres to [Semantic Versioning](https://semver.org).
2547

2648
### Fixed
2749

50+
- Html Reader/Writer Better Handling of Booleans. [PR #4257](https://github.com/PHPOffice/PhpSpreadsheet/pull/4257)
51+
- Fill Patterns/Colors When Xml Attributes are Missing. [Issue #4248](https://github.com/PHPOffice/PhpSpreadsheet/issues/4248) [PR #4250](https://github.com/PHPOffice/PhpSpreadsheet/pull/4250)
52+
- Remove Unneccesary files from Composer Package. [PR #4262](https://github.com/PHPOffice/PhpSpreadsheet/pull/4262)
2853
- Swapped row and column indexes in ReferenceHelper. [Issue #4246](https://github.com/PHPOffice/PhpSpreadsheet/issues/4246) [PR #4247](https://github.com/PHPOffice/PhpSpreadsheet/pull/4247)
2954
- Fix minor break handling drawings. [Issue #4241](https://github.com/PHPOffice/PhpSpreadsheet/issues/4241) [PR #4244](https://github.com/PHPOffice/PhpSpreadsheet/pull/4244)
3055
- Ignore cell formatting when the format is a single @. [Issue #4242](https://github.com/PHPOffice/PhpSpreadsheet/issues/4242) [PR #4243](https://github.com/PHPOffice/PhpSpreadsheet/pull/4243)
56+
- Upgrade Dompdf to Php-8.4 compatible version [PR #4267](https://github.com/PHPOffice/PhpSpreadsheet/pull/4267)
3157

3258
## 2024-11-22 - 3.5.0
3359

composer.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/PhpSpreadsheet/Calculation/Calculation.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3141,6 +3141,53 @@ private function getLocaleFile(string $localeDir, string $locale, string $langua
31413141
return $localeFileName;
31423142
}
31433143

3144+
/** @var array<int, array<int, string>> */
3145+
private static array $falseTrueArray = [];
3146+
3147+
/** @return array<int, array<int, string>> */
3148+
public function getFalseTrueArray(): array
3149+
{
3150+
if (!empty(self::$falseTrueArray)) {
3151+
return self::$falseTrueArray;
3152+
}
3153+
if (count(self::$validLocaleLanguages) == 1) {
3154+
self::loadLocales();
3155+
}
3156+
$falseTrueArray = [['FALSE'], ['TRUE']];
3157+
foreach (self::$validLocaleLanguages as $language) {
3158+
if (str_starts_with($language, 'en')) {
3159+
continue;
3160+
}
3161+
$locale = $language;
3162+
if (str_contains($locale, '_')) {
3163+
[$language] = explode('_', $locale);
3164+
}
3165+
$localeDir = implode(DIRECTORY_SEPARATOR, [__DIR__, 'locale', null]);
3166+
3167+
try {
3168+
$functionNamesFile = $this->getLocaleFile($localeDir, $locale, $language, 'functions');
3169+
} catch (Exception $e) {
3170+
continue;
3171+
}
3172+
// Retrieve the list of locale or language specific function names
3173+
$localeFunctions = file($functionNamesFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ?: [];
3174+
foreach ($localeFunctions as $localeFunction) {
3175+
[$localeFunction] = explode('##', $localeFunction); // Strip out comments
3176+
if (str_contains($localeFunction, '=')) {
3177+
[$fName, $lfName] = array_map('trim', explode('=', $localeFunction));
3178+
if ($fName === 'FALSE') {
3179+
$falseTrueArray[0][] = $lfName;
3180+
} elseif ($fName === 'TRUE') {
3181+
$falseTrueArray[1][] = $lfName;
3182+
}
3183+
}
3184+
}
3185+
}
3186+
self::$falseTrueArray = $falseTrueArray;
3187+
3188+
return $falseTrueArray;
3189+
}
3190+
31443191
/**
31453192
* Set the locale code.
31463193
*

src/PhpSpreadsheet/Collection/Memory/SimpleCache1.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
*
1010
* Alternative implementation should leverage off-memory, non-volatile storage
1111
* to reduce overall memory usage.
12+
*
13+
* Either SimpleCache1 or SimpleCache3, but not both, may be used.
14+
* For code coverage testing, it will always be SimpleCache3.
15+
*
16+
* @codeCoverageIgnore
1217
*/
1318
class SimpleCache1 implements CacheInterface
1419
{

src/PhpSpreadsheet/Helper/Sample.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use PhpOffice\PhpSpreadsheet\Spreadsheet;
1010
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
1111
use PhpOffice\PhpSpreadsheet\Writer\IWriter;
12-
use PhpOffice\PhpSpreadsheet\Writer\Pdf\Dompdf;
1312
use RecursiveDirectoryIterator;
1413
use RecursiveIteratorIterator;
1514
use RecursiveRegexIterator;
@@ -129,11 +128,7 @@ public function write(Spreadsheet $spreadsheet, string $filename, array $writers
129128
$writerCallback($writer);
130129
}
131130
$callStartTime = microtime(true);
132-
if (PHP_VERSION_ID >= 80400 && $writer instanceof Dompdf) {
133-
@$writer->save($path);
134-
} else {
135-
$writer->save($path);
136-
}
131+
$writer->save($path);
137132
$this->logWrite($writer, $path, $callStartTime);
138133
if ($this->isCli() === false) {
139134
// @codeCoverageIgnoreStart

src/PhpSpreadsheet/Reader/Csv.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,13 @@ class Csv extends BaseReader
8484
*/
8585
private static $constructorCallback;
8686

87+
/** Will be changed to false in next major release */
88+
public const DEFAULT_TEST_AUTODETECT = true;
89+
8790
/**
8891
* Attempt autodetect line endings (deprecated after PHP8.1)?
8992
*/
90-
private bool $testAutodetect = true;
93+
private bool $testAutodetect = self::DEFAULT_TEST_AUTODETECT;
9194

9295
protected bool $castFormattedNumberToNumeric = false;
9396

src/PhpSpreadsheet/Reader/Html.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use DOMElement;
88
use DOMNode;
99
use DOMText;
10+
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
1011
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
1112
use PhpOffice\PhpSpreadsheet\Cell\DataType;
1213
use PhpOffice\PhpSpreadsheet\Comment;
@@ -271,6 +272,12 @@ protected function flushCell(Worksheet $sheet, string $column, int|string $row,
271272
->setQuotePrefix(true);
272273
}
273274
}
275+
if ($datatype === DataType::TYPE_BOOL) {
276+
$cellContent = self::convertBoolean($cellContent);
277+
if (!is_bool($cellContent)) {
278+
$attributeArray['data-type'] = DataType::TYPE_STRING;
279+
}
280+
}
274281

275282
//catching the Exception and ignoring the invalid data types
276283
try {
@@ -291,6 +298,31 @@ protected function flushCell(Worksheet $sheet, string $column, int|string $row,
291298
$cellContent = (string) '';
292299
}
293300

301+
/** @var array<int, array<int, string>> */
302+
private static array $falseTrueArray = [];
303+
304+
private static function convertBoolean(?string $cellContent): bool|string
305+
{
306+
if ($cellContent === '1') {
307+
return true;
308+
}
309+
if ($cellContent === '0' || $cellContent === '' || $cellContent === null) {
310+
return false;
311+
}
312+
if (empty(self::$falseTrueArray)) {
313+
$calc = Calculation::getInstance();
314+
self::$falseTrueArray = $calc->getFalseTrueArray();
315+
}
316+
if (in_array(mb_strtoupper($cellContent), self::$falseTrueArray[1], true)) {
317+
return true;
318+
}
319+
if (in_array(mb_strtoupper($cellContent), self::$falseTrueArray[0], true)) {
320+
return false;
321+
}
322+
323+
return $cellContent;
324+
}
325+
294326
private function processDomElementBody(Worksheet $sheet, int &$row, string &$column, string &$cellContent, DOMElement $child): void
295327
{
296328
$attributeArray = [];

src/PhpSpreadsheet/Reader/Xlsx/Styles.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,22 @@ public function readFillStyle(Fill $fillStyle, SimpleXMLElement $fillStyleXml):
149149
$fillStyle->getStartColor()->setARGB($this->readColor(self::getArrayItem($gradientFill->xpath('sml:stop[@position=0]'))->color)); //* @phpstan-ignore-line
150150
$fillStyle->getEndColor()->setARGB($this->readColor(self::getArrayItem($gradientFill->xpath('sml:stop[@position=1]'))->color)); //* @phpstan-ignore-line
151151
} elseif ($fillStyleXml->patternFill) {
152-
$defaultFillStyle = Fill::FILL_NONE;
152+
$defaultFillStyle = ($fillStyle->getFillType() !== null) ? Fill::FILL_NONE : '';
153+
$fgFound = false;
154+
$bgFound = false;
153155
if ($fillStyleXml->patternFill->fgColor) {
154156
$fillStyle->getStartColor()->setARGB($this->readColor($fillStyleXml->patternFill->fgColor, true));
155-
$defaultFillStyle = Fill::FILL_SOLID;
157+
if ($fillStyle->getFillType() !== null) {
158+
$defaultFillStyle = Fill::FILL_SOLID;
159+
}
160+
$fgFound = true;
156161
}
157162
if ($fillStyleXml->patternFill->bgColor) {
158163
$fillStyle->getEndColor()->setARGB($this->readColor($fillStyleXml->patternFill->bgColor, true));
159-
$defaultFillStyle = Fill::FILL_SOLID;
164+
if ($fillStyle->getFillType() !== null) {
165+
$defaultFillStyle = Fill::FILL_SOLID;
166+
}
167+
$bgFound = true;
160168
}
161169

162170
$type = '';
@@ -169,6 +177,22 @@ public function readFillStyle(Fill $fillStyle, SimpleXMLElement $fillStyleXml):
169177
$patternType = ($type === '') ? $defaultFillStyle : $type;
170178

171179
$fillStyle->setFillType($patternType);
180+
if (
181+
!$fgFound // no foreground color specified
182+
&& !in_array($patternType, [Fill::FILL_NONE, Fill::FILL_SOLID], true) // these patterns aren't relevant
183+
&& $fillStyle->getStartColor()->getARGB() // not conditional
184+
) {
185+
$fillStyle->getStartColor()
186+
->setARGB('', true);
187+
}
188+
if (
189+
!$bgFound // no background color specified
190+
&& !in_array($patternType, [Fill::FILL_NONE, Fill::FILL_SOLID], true) // these patterns aren't relevant
191+
&& $fillStyle->getEndColor()->getARGB() // not conditional
192+
) {
193+
$fillStyle->getEndColor()
194+
->setARGB('', true);
195+
}
172196
}
173197
}
174198

src/PhpSpreadsheet/Style/Color.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,14 @@ public function getARGB(): ?string
230230
*
231231
* @return $this
232232
*/
233-
public function setARGB(?string $colorValue = self::COLOR_BLACK): static
233+
public function setARGB(?string $colorValue = self::COLOR_BLACK, bool $nullStringOkay = false): static
234234
{
235235
$this->hasChanged = true;
236-
$colorValue = $this->validateColor($colorValue);
237-
if ($colorValue === '') {
238-
return $this;
236+
if (!$nullStringOkay || $colorValue !== '') {
237+
$colorValue = $this->validateColor($colorValue);
238+
if ($colorValue === '') {
239+
return $this;
240+
}
239241
}
240242

241243
if ($this->isSupervisor) {

0 commit comments

Comments
 (0)