Skip to content

Commit 1972cb1

Browse files
authored
Merge branch 'master' into issue4246
2 parents 54fd177 + a069960 commit 1972cb1

File tree

557 files changed

+1437
-3758
lines changed

Some content is hidden

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

557 files changed

+1437
-3758
lines changed

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
'ordered_imports' => true,
147147
'ordered_interfaces' => true,
148148
'ordered_traits' => true,
149+
'php_unit_attributes' => ['keep_annotations' => false],
149150
'php_unit_construct' => true,
150151
'php_unit_dedicate_assert' => true,
151152
'php_unit_dedicate_assert_internal_type' => true,

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ and this project adheres to [Semantic Versioning](https://semver.org).
2626
### Fixed
2727

2828
- 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)
29+
- Fix minor break handling drawings. [Issue #4241](https://github.com/PHPOffice/PhpSpreadsheet/issues/4241) [PR #4244](https://github.com/PHPOffice/PhpSpreadsheet/pull/4244)
30+
- 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)
2931

3032
## 2024-11-22 - 3.5.0
3133

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ This makes it easier to see exactly what is being tested when reviewing the PR.
4040
2. Tag subject must be the version number, eg: `1.2.3`
4141
3. Tag body must be a copy-paste of the changelog entries.
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.
43-
4. By default, Github remove 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 ';'`.
43+
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

4545
> **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.
4646
- release1291

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
"phpcompatibility/php-compatibility": "^9.3",
9696
"phpstan/phpstan": "^1.1",
9797
"phpstan/phpstan-phpunit": "^1.0",
98-
"phpunit/phpunit": "^9.6 || ^10.5",
98+
"phpunit/phpunit": "^10.5",
9999
"squizlabs/php_codesniffer": "^3.7",
100100
"tecnickcom/tcpdf": "^6.5"
101101
},

docs/topics/recipes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,8 +1293,8 @@ style object:
12931293

12941294
```php
12951295
$spreadsheet->getActiveSheet()
1296-
->duplicateStyle(
1297-
$spreadsheet->getActiveSheet()->getStyle('B2'),
1296+
->duplicateConditionalStyle(
1297+
$spreadsheet->getActiveSheet()->getConditionalStyles('B2'),
12981298
'B3:B7'
12991299
);
13001300
```

phpunit.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<coverage/>
44
<php>
55
<ini name="memory_limit" value="2048M"/>
6+
<ini name="error_reporting" value="E_ALL"/>
67
</php>
78
<testsuite name="PhpSpreadsheet Unit Test Suite">
89
<directory>./tests/PhpSpreadsheetTests</directory>

phpunit9.xml.dist

Lines changed: 0 additions & 15 deletions
This file was deleted.

samples/Basic4/53_ImageOpacity.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
use PhpOffice\PhpSpreadsheet\Spreadsheet;
66
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
77

8-
//var_dump(realpath(__DIR__ . '/../images/blue_square.png'));
9-
//exit();
10-
118
$path = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'images/blue_square.png';
129
$spreadsheet = new Spreadsheet();
1310
$spreadsheet->getProperties()->setTitle('53_ImageOpacity');
@@ -33,12 +30,12 @@
3330
$drawing->setWorksheet($sheet);
3431

3532
$drawing = new Drawing();
33+
$drawing->setWorksheet($sheet);
3634
$drawing->setName('Blue Square opacity 60%');
3735
$drawing->setPath($path);
3836
$drawing->setCoordinates('E1');
3937
$drawing->setCoordinates2('F5');
4038
$drawing->setOpacity(60000);
41-
$drawing->setWorksheet($sheet);
4239

4340
$drawing = new Drawing();
4441
$drawing->setName('Blue Square opacity 40%');
@@ -57,12 +54,12 @@
5754
$drawing->setWorksheet($sheet);
5855

5956
$drawing = new Drawing();
57+
$drawing->setWorksheet($sheet);
6058
$drawing->setName('Blue Square opacity 0%');
6159
$drawing->setPath($path);
6260
$drawing->setCoordinates('E8');
6361
$drawing->setCoordinates2('F12');
6462
$drawing->setOpacity(0);
65-
$drawing->setWorksheet($sheet);
6663

6764
// Save
6865
$helper->write($spreadsheet, __FILE__, ['Xlsx', 'Html', 'Dompdf', 'Mpdf']);

src/PhpSpreadsheet/Style/NumberFormat/Formatter.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Formatter extends BaseFormatter
1414
* Matches any @ symbol that isn't enclosed in quotes.
1515
*/
1616
private const SYMBOL_AT = '/@(?=(?:[^"]*"[^"]*")*[^"]*\Z)/miu';
17+
private const QUOTE_REPLACEMENT = "\u{fffe}"; // invalid Unicode character
1718

1819
/**
1920
* Matches any ; symbol that isn't enclosed in quotes, for a "section" split.
@@ -125,8 +126,23 @@ public static function toFormattedString($value, string $format, ?array $callBac
125126
}
126127
// For now we do not treat strings in sections, although section 4 of a format code affects strings
127128
// Process a single block format code containing @ for text substitution
128-
if (preg_match(self::SECTION_SPLIT, $format) === 0 && preg_match(self::SYMBOL_AT, $format) === 1) {
129-
return str_replace('"', '', preg_replace(self::SYMBOL_AT, (string) $value, $format) ?? '');
129+
$formatx = str_replace('\\"', self::QUOTE_REPLACEMENT, $format);
130+
if (preg_match(self::SECTION_SPLIT, $format) === 0 && preg_match(self::SYMBOL_AT, $formatx) === 1) {
131+
if (!str_contains($format, '"')) {
132+
return str_replace('@', $value, $format);
133+
}
134+
//escape any dollar signs on the string, so they are not replaced with an empty value
135+
$value = str_replace(
136+
['$', '"'],
137+
['\\$', self::QUOTE_REPLACEMENT],
138+
(string) $value
139+
);
140+
141+
return str_replace(
142+
['"', self::QUOTE_REPLACEMENT],
143+
['', '"'],
144+
preg_replace(self::SYMBOL_AT, $value, $formatx) ?? $value
145+
);
130146
}
131147

132148
// If we have a text value, return it "as is"

src/PhpSpreadsheet/Worksheet/BaseDrawing.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,18 @@ public function getWorksheet(): ?Worksheet
197197
public function setWorksheet(?Worksheet $worksheet = null, bool $overrideOld = false): self
198198
{
199199
if ($this->worksheet === null) {
200-
// Add drawing to \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet
201-
if ($worksheet !== null && !($this instanceof Drawing && $this->getPath() === '')) {
200+
// Add drawing to Worksheet
201+
if ($worksheet !== null) {
202202
$this->worksheet = $worksheet;
203-
$this->worksheet->getCell($this->coordinates);
204-
$this->worksheet->getDrawingCollection()->append($this);
203+
if (!($this instanceof Drawing && $this->getPath() === '')) {
204+
$this->worksheet->getCell($this->coordinates);
205+
}
206+
$this->worksheet->getDrawingCollection()
207+
->append($this);
205208
}
206209
} else {
207210
if ($overrideOld) {
208-
// Remove drawing from old \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet
211+
// Remove drawing from old Worksheet
209212
$iterator = $this->worksheet->getDrawingCollection()->getIterator();
210213

211214
while ($iterator->valid()) {
@@ -217,10 +220,10 @@ public function setWorksheet(?Worksheet $worksheet = null, bool $overrideOld = f
217220
}
218221
}
219222

220-
// Set new \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet
223+
// Set new Worksheet
221224
$this->setWorksheet($worksheet);
222225
} else {
223-
throw new PhpSpreadsheetException('A Worksheet has already been assigned. Drawings can only exist on one \\PhpOffice\\PhpSpreadsheet\\Worksheet.');
226+
throw new PhpSpreadsheetException('A Worksheet has already been assigned. Drawings can only exist on one Worksheet.');
224227
}
225228
}
226229

@@ -235,6 +238,11 @@ public function getCoordinates(): string
235238
public function setCoordinates(string $coordinates): self
236239
{
237240
$this->coordinates = $coordinates;
241+
if ($this->worksheet !== null) {
242+
if (!($this instanceof Drawing && $this->getPath() === '')) {
243+
$this->worksheet->getCell($this->coordinates);
244+
}
245+
}
238246

239247
return $this;
240248
}

0 commit comments

Comments
 (0)