Skip to content

Commit f00ebda

Browse files
authored
Merge branch 'master' into currsymbol
2 parents b8f2aa9 + 1721aa4 commit f00ebda

24 files changed

+375
-130
lines changed

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ and this project adheres to [Semantic Versioning](https://semver.org).
2525

2626
### Fixed
2727

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-
- Avoid unexpected charset in currency symbol. [PR #4279](https://github.com/PHPOffice/PhpSpreadsheet/pull/4279)
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+
- Avoid unexpected charset in currency symbol. [PR #4279](https://github.com/PHPOffice/PhpSpreadsheet/pull/4279)
30+
- Add forceFullCalc option to Xlsx Writer. [Issue #4269](https://github.com/PHPOffice/PhpSpreadsheet/issues/4269) [PR #4271](https://github.com/PHPOffice/PhpSpreadsheet/pull/4271)
31+
- 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)
32+
- Coverage-related tweaks to Xls Reader. [PR #4277](https://github.com/PHPOffice/PhpSpreadsheet/pull/4277)
33+
- Several fixed to ODS Writer. [Issue #4261](https://github.com/PHPOffice/PhpSpreadsheet/issues/4261) [PR #4263](https://github.com/PHPOffice/PhpSpreadsheet/pull/4263) [PR #4264](https://github.com/PHPOffice/PhpSpreadsheet/pull/4264) [PR #4266](https://github.com/PHPOffice/PhpSpreadsheet/pull/4266)
3034

3135
## 2024-12-08 - 3.6.0
3236

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ $writer->save("05featuredemo.xlsx");
169169
**Note** Formulas will still be calculated in any column set to be autosized
170170
even if pre-calculated is set to false
171171

172+
**Note** Prior to release 3.7.0, the use of this feature will cause Excel to be used in a mode where opening a sheet saved in this manner *might* not automatically recalculate a cell's formula when a cell used it the formula changes. Furthermore, that behavior might be applied to all spreadsheets open at the time. To avoid this behavior, add the following statement after `setPreCalculateFormulas` above:
173+
```php
174+
$writer->setForceFullCalc(false);
175+
```
176+
In a future release, the property's default may change to `false` and that statement may no longer be required.
177+
172178
#### Office 2003 compatibility pack
173179

174180
Because of a bug in the Office2003 compatibility pack, there can be some

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/Reader/Xls/Color.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ public static function map(int $color, array $palette, int $version): array
2424
return $palette[$color - 8];
2525
}
2626

27-
// default color table
28-
if ($version == Xls::XLS_BIFF8) {
29-
return Color\BIFF8::lookup($color);
30-
}
31-
32-
// BIFF5
33-
return Color\BIFF5::lookup($color);
27+
return ($version === Xls::XLS_BIFF8) ? Color\BIFF8::lookup($color) : Color\BIFF5::lookup($color);
3428
}
3529
}

src/PhpSpreadsheet/Reader/Xls/ConditionalFormatting.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,12 @@ class ConditionalFormatting extends Xls
3636

3737
public static function type(int $type): ?string
3838
{
39-
if (isset(self::$types[$type])) {
40-
return self::$types[$type];
41-
}
42-
43-
return null;
39+
return self::$types[$type] ?? null;
4440
}
4541

4642
public static function operator(int $operator): ?string
4743
{
48-
if (isset(self::$operators[$operator])) {
49-
return self::$operators[$operator];
50-
}
51-
52-
return null;
44+
return self::$operators[$operator] ?? null;
5345
}
5446

5547
/**

src/PhpSpreadsheet/Reader/Xls/DataValidationHelper.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,29 +48,17 @@ class DataValidationHelper extends Xls
4848

4949
public static function type(int $type): ?string
5050
{
51-
if (isset(self::$types[$type])) {
52-
return self::$types[$type];
53-
}
54-
55-
return null;
51+
return self::$types[$type] ?? null;
5652
}
5753

5854
public static function errorStyle(int $errorStyle): ?string
5955
{
60-
if (isset(self::$errorStyles[$errorStyle])) {
61-
return self::$errorStyles[$errorStyle];
62-
}
63-
64-
return null;
56+
return self::$errorStyles[$errorStyle] ?? null;
6557
}
6658

6759
public static function operator(int $operator): ?string
6860
{
69-
if (isset(self::$operators[$operator])) {
70-
return self::$operators[$operator];
71-
}
72-
73-
return null;
61+
return self::$operators[$operator] ?? null;
7462
}
7563

7664
/**

src/PhpSpreadsheet/Reader/Xls/ListFunctions.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,10 @@ protected function listWorksheetNames2(string $filename, Xls $xls): array
4444
}
4545

4646
foreach ($xls->sheets as $sheet) {
47-
if ($sheet['sheetType'] != 0x00) {
47+
if ($sheet['sheetType'] === 0x00) {
4848
// 0x00: Worksheet, 0x02: Chart, 0x06: Visual Basic module
49-
continue;
49+
$worksheetNames[] = $sheet['name'];
5050
}
51-
52-
$worksheetNames[] = $sheet['name'];
5351
}
5452

5553
return $worksheetNames;
@@ -93,7 +91,7 @@ protected function listWorksheetInfo2(string $filename, Xls $xls): array
9391

9492
// Parse the individual sheets
9593
foreach ($xls->sheets as $sheet) {
96-
if ($sheet['sheetType'] != 0x00) {
94+
if ($sheet['sheetType'] !== 0x00) {
9795
// 0x00: Worksheet
9896
// 0x02: Chart
9997
// 0x06: Visual Basic module

src/PhpSpreadsheet/Reader/Xls/Style/Border.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ class Border
2828

2929
public static function lookup(int $index): string
3030
{
31-
if (isset(self::$borderStyleMap[$index])) {
32-
return self::$borderStyleMap[$index];
33-
}
34-
35-
return StyleBorder::BORDER_NONE;
31+
return self::$borderStyleMap[$index] ?? StyleBorder::BORDER_NONE;
3632
}
3733
}

src/PhpSpreadsheet/Reader/Xls/Style/FillPattern.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ class FillPattern
3737
*/
3838
public static function lookup(int $index): string
3939
{
40-
if (isset(self::$fillPatternMap[$index])) {
41-
return self::$fillPatternMap[$index];
42-
}
43-
44-
return Fill::FILL_NONE;
40+
return self::$fillPatternMap[$index] ?? Fill::FILL_NONE;
4541
}
4642
}

src/PhpSpreadsheet/Writer/Ods/Cell/Style.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Style
2020
public const COLUMN_STYLE_PREFIX = 'co';
2121
public const ROW_STYLE_PREFIX = 'ro';
2222
public const TABLE_STYLE_PREFIX = 'ta';
23+
public const INDENT_TO_INCHES = 0.1043; // undocumented, used trial and error
2324

2425
private XMLWriter $writer;
2526

@@ -28,12 +29,13 @@ public function __construct(XMLWriter $writer)
2829
$this->writer = $writer;
2930
}
3031

31-
private function mapHorizontalAlignment(string $horizontalAlignment): string
32+
private function mapHorizontalAlignment(?string $horizontalAlignment): string
3233
{
3334
return match ($horizontalAlignment) {
3435
Alignment::HORIZONTAL_CENTER, Alignment::HORIZONTAL_CENTER_CONTINUOUS, Alignment::HORIZONTAL_DISTRIBUTED => 'center',
3536
Alignment::HORIZONTAL_RIGHT => 'end',
3637
Alignment::HORIZONTAL_FILL, Alignment::HORIZONTAL_JUSTIFY => 'justify',
38+
Alignment::HORIZONTAL_GENERAL, '', null => '',
3739
default => 'start',
3840
};
3941
}
@@ -145,8 +147,10 @@ private function writeCellProperties(CellStyle $style): void
145147
{
146148
// Align
147149
$hAlign = $style->getAlignment()->getHorizontal();
150+
$hAlign = $this->mapHorizontalAlignment($hAlign);
148151
$vAlign = $style->getAlignment()->getVertical();
149152
$wrap = $style->getAlignment()->getWrapText();
153+
$indent = $style->getAlignment()->getIndent();
150154

151155
$this->writer->startElement('style:table-cell-properties');
152156
if (!empty($vAlign) || $wrap) {
@@ -168,10 +172,16 @@ private function writeCellProperties(CellStyle $style): void
168172

169173
$this->writer->endElement();
170174

171-
if (!empty($hAlign)) {
172-
$hAlign = $this->mapHorizontalAlignment($hAlign);
173-
$this->writer->startElement('style:paragraph-properties');
174-
$this->writer->writeAttribute('fo:text-align', $hAlign);
175+
if ($hAlign !== '' || !empty($indent)) {
176+
$this->writer
177+
->startElement('style:paragraph-properties');
178+
if ($hAlign !== '') {
179+
$this->writer->writeAttribute('fo:text-align', $hAlign);
180+
}
181+
if (!empty($indent)) {
182+
$indentString = sprintf('%.4f', $indent * self::INDENT_TO_INCHES) . 'in';
183+
$this->writer->writeAttribute('fo:margin-left', $indentString);
184+
}
175185
$this->writer->endElement();
176186
}
177187
}
@@ -289,6 +299,7 @@ public function writeTableStyle(Worksheet $worksheet, int $sheetId): void
289299
'style:name',
290300
sprintf('%s%d', self::TABLE_STYLE_PREFIX, $sheetId)
291301
);
302+
$this->writer->writeAttribute('style:master-page-name', 'Default');
292303

293304
$this->writer->startElement('style:table-properties');
294305

0 commit comments

Comments
 (0)