Skip to content

Commit 65f7158

Browse files
authored
Merge pull request #4340 from oleibman/chgdefault
Breaking Change - 3 Defaults
2 parents 6abfe2f + ed5ea6d commit 65f7158

File tree

13 files changed

+45
-35
lines changed

13 files changed

+45
-35
lines changed

CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org).
1111

1212
- Data Validations will be stored by worksheet, not cell. Index can be one or more cells or cell ranges. [Issue #797](https://github.com/PHPOffice/PhpSpreadsheet/issues/797) [Issue #4091](https://github.com/PHPOffice/PhpSpreadsheet/issues/4091) [Issue #4206](https://github.com/PHPOffice/PhpSpreadsheet/issues/4206) [PR #4240](https://github.com/PHPOffice/PhpSpreadsheet/pull/4240)
1313
- Conditional Formatting adds Priority property and handles overlapping ranges better. [Issue #4312](https://github.com/PHPOffice/PhpSpreadsheet/issues/4312) [Issue #4318](https://github.com/PHPOffice/PhpSpreadsheet/issues/4318) [PR #4314](https://github.com/PHPOffice/PhpSpreadsheet/pull/4314)
14+
- Csv Reader will no longer auto-detect Mac line endings by default. Prior behavior can be explicitly enabled via `setTestAutoDetect(true)`, and it will not be possible at all with Php9+. [Issue #4092](https://github.com/PHPOffice/PhpSpreadsheet/issues/4092) [PR #4340](https://github.com/PHPOffice/PhpSpreadsheet/pull/4340)
15+
- Html Writer will now use "better boolean" logic. Booleans will now be output by default as TRUE/FALSE rather than 1/null-string. Prior behavior can be explicitly enabled via `setBetterBoolean(false)`. [PR #4340](https://github.com/PHPOffice/PhpSpreadsheet/pull/4340)
16+
- Xlsx Writer will now use false as the default for `forceFullCalc`. This affects writes with `preCalculateFormulas` set to false. Prior behavior can be explicitly enabled via `setForceFullCalc(null)`.[PR #4340](https://github.com/PHPOffice/PhpSpreadsheet/pull/4340)
1417
- Deletion of items deprecated in Release 3. See "removed" below.
1518

1619
### Added
@@ -35,7 +38,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
3538

3639
### Fixed
3740

38-
- Xls writer Parser Mishandling True/False Argument. [Issue #4331](https://github.com/PHPOffice/PhpSpreadsheet/issues/4331) [PR #4333](https://github.com/PHPOffice/PhpSpreadsheet/pull/4333)
41+
- Xls Writer Parser Mishandling True/False Argument. [Issue #4331](https://github.com/PHPOffice/PhpSpreadsheet/issues/4331) [PR #4333](https://github.com/PHPOffice/PhpSpreadsheet/pull/4333)
3942

4043
## 2025-01-26 - 3.9.0
4144

CONTRIBUTING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ This makes it easier to see exactly what is being tested when reviewing the PR.
4242
3. Push the tag with `git push --tags`, GitHub Actions will create a GitHub release automatically, and the release details will automatically be sent to packagist.
4343
4. By default, Github removes markdown headings in the Release Notes. You can either edit to restore these, or, probably preferably, change the default comment character on your system - `git config core.commentChar ";"`.
4444

45-
> **Note:** Tagged releases are made from the `master` branch. Only in an emergency should a tagged release be made from the `release` branch. (i.e. cherry-picked hot-fixes.) However, there are 3 branches which have been updated to apply security patches, and those may be tagged if future security updates are needed.
45+
> **Note:** Tagged releases are made from the `master` branch. Only in an emergency should a tagged release be made from the `release` branch. (i.e. cherry-picked hot-fixes.) However, there are 4 branches which have been updated to apply security patches, and those may be tagged if future security updates are needed.
4646
- release1291
4747
- release210
4848
- release222
49-
49+
- release390

docs/topics/reading-and-writing-to-file.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ even if pre-calculated is set to false
173173
```php
174174
$writer->setForceFullCalc(false);
175175
```
176-
In a future release, the property's default may change to `false` and that statement may no longer be required.
176+
Starting with Release 4.0.0, the property's default is changed to `false` and that statement is no longer be required. The property can be set to `null` if the old behavior is needed.
177177

178178
#### Office 2003 compatibility pack
179179

@@ -594,6 +594,9 @@ You can suppress testing for Mac line endings as follows:
594594
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Csv();
595595
$reader->setTestAutoDetect(false);
596596
```
597+
Starting with Release 4.0.0, the property defaults to `false`,
598+
so the statement above is no longer needed. The old behavior
599+
can be enabled by setting the property to `true`.
597600

598601
### \PhpOffice\PhpSpreadsheet\Writer\Csv
599602

src/PhpSpreadsheet/Reader/Csv.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ 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;
87+
/** Changed from true to false in release 4.0.0 */
88+
public const DEFAULT_TEST_AUTODETECT = false;
8989

9090
/**
9191
* Attempt autodetect line endings (deprecated after PHP8.1)?

src/PhpSpreadsheet/Writer/Html.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class Html extends BaseWriter
143143
/** @var Chart[] */
144144
private $sheetCharts;
145145

146-
private bool $betterBoolean = false;
146+
private bool $betterBoolean = true;
147147

148148
private string $getTrue = 'TRUE';
149149

@@ -1494,7 +1494,7 @@ private function generateRowWriteCell(
14941494
$dataType = $worksheet->getCell($coordinate)->getDataType();
14951495
if ($dataType === DataType::TYPE_BOOL) {
14961496
$html .= ' data-type="' . DataType::TYPE_BOOL . '"';
1497-
} elseif ($dataType === DataType::TYPE_FORMULA && is_bool($worksheet->getCell($coordinate)->getCalculatedValue())) {
1497+
} elseif ($dataType === DataType::TYPE_FORMULA && $this->preCalculateFormulas && is_bool($worksheet->getCell($coordinate)->getCalculatedValue())) {
14981498
$html .= ' data-type="' . DataType::TYPE_BOOL . '"';
14991499
} elseif (is_numeric($cellData) && $worksheet->getCell($coordinate)->getDataType() === DataType::TYPE_STRING) {
15001500
$html .= ' data-type="' . DataType::TYPE_STRING . '"';

src/PhpSpreadsheet/Writer/Xlsx.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ class Xlsx extends BaseWriter
140140

141141
private bool $useDynamicArray = false;
142142

143-
private ?bool $forceFullCalc = null;
143+
public const DEFAULT_FORCE_FULL_CALC = false;
144+
145+
// Default changed from null in PhpSpreadsheet 4.0.0.
146+
private ?bool $forceFullCalc = self::DEFAULT_FORCE_FULL_CALC;
144147

145148
/**
146149
* Create a new Xlsx Writer.
@@ -758,6 +761,7 @@ private function determineUseDynamicArrays(): void
758761
* If null, this will be set to the opposite of $preCalculateFormulas.
759762
* It is likely that false is the desired setting, although
760763
* cases have been reported where true is required (issue #456).
764+
* Nevertheless, default is set to false in PhpSpreadsheet 4.0.0.
761765
*/
762766
public function setForceFullCalc(?bool $forceFullCalc): self
763767
{

tests/PhpSpreadsheetTests/Reader/Csv/CsvLineEndingTest.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PhpOffice\PhpSpreadsheet\Reader\Csv;
88
use PhpOffice\PhpSpreadsheet\Shared\File;
9+
use PHPUnit\Framework\Attributes\DataProvider;
910
use PHPUnit\Framework\TestCase;
1011

1112
class CsvLineEndingTest extends TestCase
@@ -22,7 +23,7 @@ protected function tearDown(): void
2223
}
2324
}
2425

25-
#[\PHPUnit\Framework\Attributes\DataProvider('providerEndings')]
26+
#[DataProvider('providerEndings')]
2627
public function testEndings(string $ending): void
2728
{
2829
if ($ending === "\r" && PHP_VERSION_ID >= 90000) {
@@ -43,14 +44,14 @@ public function testEndings(string $ending): void
4344
$spreadsheet->disconnectWorksheets();
4445
}
4546

46-
#[\PHPUnit\Framework\Attributes\DataProvider('providerEndings')]
47+
#[DataProvider('providerEndings')]
4748
public function testEndingsNoDetect(string $ending): void
4849
{
4950
$this->tempFile = $filename = File::temporaryFilename();
5051
$data = ['123', '456', '789'];
5152
file_put_contents($filename, implode($ending, $data));
5253
$reader = new Csv();
53-
$reader->setTestAutoDetect(false);
54+
self::assertSame(self::$alwaysFalse, Csv::DEFAULT_TEST_AUTODETECT);
5455
$spreadsheet = $reader->load($filename);
5556
$sheet = $spreadsheet->getActiveSheet();
5657
if ($ending === "\r") {

tests/PhpSpreadsheetTests/Reader/Xlsx/Issue4248Test.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function testHtml(): void
9494
. ' <td class="column0 style0">&nbsp;</td>'
9595
. ' <td class="column1 style28 null"></td>'
9696
. ' <td class="column2 style35 s">Eligible </td>'
97-
. ' <td class="column3 style70 f">Non</td>';
97+
. ' <td class="column3 style70 s">Non</td>';
9898
self::assertStringContainsString($expected, $data, 'Cell D18 style');
9999
$expected = ' td.style70, th.style70 { vertical-align:middle; text-align:center; border-bottom:1px solid #000000 !important; border-top:2px solid #000000 !important; border-left:2px solid #000000 !important; border-right:1px solid #000000 !important; font-weight:bold; color:#000000; font-family:\'Calibri\'; font-size:16pt; background-color:#BDD7EE }';
100100
self::assertStringContainsString($expected, $data, 'background color');

tests/PhpSpreadsheetTests/Writer/Html/BadHyperlinkTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function testBadHyperlink(): void
1818
$spreadsheet = $reader->load($infile);
1919
$writer = new HtmlWriter($spreadsheet);
2020
$html = $writer->generateHtmlAll();
21-
self::assertStringContainsString('<td class="column0 style1 f">jav&#9;ascript:alert()</td>', $html);
21+
self::assertStringContainsString('<td class="column0 style1 s">jav&#9;ascript:alert()</td>', $html);
2222
$spreadsheet->disconnectWorksheets();
2323
}
2424

@@ -29,7 +29,7 @@ public function testControlCharacter(): void
2929
$spreadsheet = $reader->load($infile);
3030
$writer = new HtmlWriter($spreadsheet);
3131
$html = $writer->generateHtmlAll();
32-
self::assertStringContainsString('<td class="column0 style0 f">&#20;j&#13;avascript:alert(1)</td>', $html);
32+
self::assertStringContainsString('<td class="column0 style0 s">&#20;j&#13;avascript:alert(1)</td>', $html);
3333
$spreadsheet->disconnectWorksheets();
3434
}
3535
}

tests/PhpSpreadsheetTests/Writer/Html/BetterBooleanTest.php

+6-14
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public function testDefault(): void
3131
{
3232
$spreadsheet = new Spreadsheet();
3333
$writer = new HtmlWriter($spreadsheet);
34-
// Default will change with next PhpSpreadsheet release
35-
self::assertFalse($writer->getBetterBoolean());
34+
// Default change with release 4.0.0
35+
self::assertTrue($writer->getBetterBoolean());
3636
$spreadsheet->disconnectWorksheets();
3737
}
3838

@@ -58,9 +58,7 @@ public function testBetterBoolean(): void
5858
$sheet->getCell('F1')->setValue('="A"&"B"');
5959
$sheet->getCell('G1')->setValue('=1+2');
6060

61-
/** @var callable */
62-
$callableWriter = [$this, 'setBetter'];
63-
$reloaded = $this->writeAndReload($spreadsheet, 'Html', null, $callableWriter);
61+
$reloaded = $this->writeAndReload($spreadsheet, 'Html');
6462
$spreadsheet->disconnectWorksheets();
6563

6664
$rsheet = $reloaded->getActiveSheet();
@@ -86,9 +84,7 @@ public function testNotBetterBoolean(): void
8684
$sheet->getCell('F1')->setValue('="A"&"B"');
8785
$sheet->getCell('G1')->setValue('=1+2');
8886

89-
/** @var callable */
90-
$callableWriter = [$this, 'setNotBetter'];
91-
$reloaded = $this->writeAndReload($spreadsheet, 'Html', null, $callableWriter);
87+
$reloaded = $this->writeAndReload($spreadsheet, 'Html', null, $this->setNotBetter(...));
9288
$spreadsheet->disconnectWorksheets();
9389

9490
$rsheet = $reloaded->getActiveSheet();
@@ -125,9 +121,7 @@ public function testLocale(): void
125121
self::assertStringContainsString('<td class="column5 style0 s">AB</td>', $html);
126122
self::assertStringContainsString('<td class="column6 style0 n">3</td>', $html);
127123

128-
/** @var callable */
129-
$callableWriter = [$this, 'setBetter'];
130-
$reloaded = $this->writeAndReload($spreadsheet, 'Html', null, $callableWriter);
124+
$reloaded = $this->writeAndReload($spreadsheet, 'Html', null, $this->setBetter(...));
131125
$spreadsheet->disconnectWorksheets();
132126

133127
$rsheet = $reloaded->getActiveSheet();
@@ -169,9 +163,7 @@ public function testInline(): void
169163
self::assertStringContainsString('<td style="text-align:left;">AB</td>', $html);
170164
self::assertStringContainsString('<td style="text-align:right;">3</td>', $html);
171165

172-
/** @var callable */
173-
$callableWriter = [$this, 'setBetter'];
174-
$reloaded = $this->writeAndReload($spreadsheet, 'Html', null, $callableWriter);
166+
$reloaded = $this->writeAndReload($spreadsheet, 'Html', null, $this->setBetter(...));
175167
$spreadsheet->disconnectWorksheets();
176168

177169
$rsheet = $reloaded->getActiveSheet();

tests/PhpSpreadsheetTests/Writer/Html/NoJavascriptLinksTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testNoJavascriptLinks(): void
2727
$html = $writer->generateHTMLAll();
2828
self::assertStringContainsString('<td class="column0 style0 s"><a href="http://www.example.com">Click me</a></td>', $html, 'http hyperlink retained');
2929
self::assertStringContainsString('<td class="column0 style0 s">javascript:alert(\'hello1\')</td>', $html, 'javascript hyperlink dropped');
30-
self::assertStringContainsString('<td class="column0 style0 f">javascript:alert(\'hello2\')</td>', $html, 'javascript hyperlink function dropped');
30+
self::assertStringContainsString('<td class="column0 style0 s">javascript:alert(\'hello2\')</td>', $html, 'javascript hyperlink function dropped');
3131
$spreadsheet->disconnectWorksheets();
3232
}
3333
}

tests/PhpSpreadsheetTests/Writer/PreCalcTest.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PhpOffice\PhpSpreadsheet\Spreadsheet;
1111
use PhpOffice\PhpSpreadsheet\Worksheet\ColumnDimension;
1212
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
13+
use PHPUnit\Framework\Attributes\DataProvider;
1314

1415
class PreCalcTest extends AbstractFunctional
1516
{
@@ -117,7 +118,7 @@ private function verifyXlsx(?bool $preCalc, string $type): void
117118
$data = self::readFile($file);
118119
// confirm whether workbook is set to recalculate
119120
if ($preCalc === false) {
120-
self::assertStringContainsString('<calcPr calcId="999999" calcMode="auto" calcCompleted="0" fullCalcOnLoad="1" forceFullCalc="1"/>', $data);
121+
self::assertStringContainsString('<calcPr calcId="999999" calcMode="auto" calcCompleted="0" fullCalcOnLoad="1" forceFullCalc="0"/>', $data);
121122
} else {
122123
self::assertStringContainsString('<calcPr calcId="999999" calcMode="auto" calcCompleted="1" fullCalcOnLoad="0" forceFullCalc="0"/>', $data);
123124
}
@@ -174,7 +175,7 @@ private function verifyCsv(?bool $preCalc, string $type): void
174175
}
175176
}
176177

177-
#[\PHPUnit\Framework\Attributes\DataProvider('providerPreCalc')]
178+
#[DataProvider('providerPreCalc')]
178179
public function testPreCalc(?bool $preCalc, string $type): void
179180
{
180181
$spreadsheet = new Spreadsheet();
@@ -203,5 +204,6 @@ public function testPreCalc(?bool $preCalc, string $type): void
203204
$this->verifyOds($preCalc, $type);
204205
$this->verifyHtml($preCalc, $type);
205206
$this->verifyCsv($preCalc, $type);
207+
$spreadsheet->disconnectWorksheets();
206208
}
207209
}

tests/PhpSpreadsheetTests/Writer/Xlsx/Issue4269Test.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class Issue4269Test extends TestCase
1414
{
1515
private string $outputFile = '';
1616

17+
private static bool $alwaysFalse = false;
18+
1719
protected function tearDown(): void
1820
{
1921
if ($this->outputFile !== '') {
@@ -35,9 +37,7 @@ public function testWriteArrayFormulaTextJoin(
3537

3638
$writer = new XlsxWriter($spreadsheet);
3739
$writer->setPreCalculateFormulas($preCalculateFormulas);
38-
if ($forceFullCalc !== null) {
39-
$writer->setForceFullCalc($forceFullCalc);
40-
}
40+
$writer->setForceFullCalc($forceFullCalc);
4141
$this->outputFile = File::temporaryFilename();
4242
$writer->save($this->outputFile);
4343
$spreadsheet->disconnectWorksheets();
@@ -62,4 +62,9 @@ public static function validationProvider(): array
6262
'unlikely use case' => [true, true, 'calcMode="auto" calcCompleted="1" fullCalcOnLoad="0" forceFullCalc="1"'],
6363
];
6464
}
65+
66+
public function testDefault(): void
67+
{
68+
self::assertSame(self::$alwaysFalse, XlsxWriter::DEFAULT_FORCE_FULL_CALC);
69+
}
6570
}

0 commit comments

Comments
 (0)