Skip to content

Commit 915bfc5

Browse files
authored
Merge pull request #4212 from oleibman/issue4200
Write ignoredErrors Tag Before Drawings
2 parents ce32cba + aba2385 commit 915bfc5

File tree

3 files changed

+94
-3
lines changed

3 files changed

+94
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
3737
- Option to Write Hyperlink Rather Than Label to Csv. [Issue #1412](https://github.com/PHPOffice/PhpSpreadsheet/issues/1412) [PR #4151](https://github.com/PHPOffice/PhpSpreadsheet/pull/4151)
3838
- Invalid Html Due to Cached Filesize. [Issue #1107](https://github.com/PHPOffice/PhpSpreadsheet/issues/1107) [PR #4184](https://github.com/PHPOffice/PhpSpreadsheet/pull/4184)
3939
- Excel 2003 Allows Html Entities. [Issue #2157](https://github.com/PHPOffice/PhpSpreadsheet/issues/2157) [PR #4187](https://github.com/PHPOffice/PhpSpreadsheet/pull/4187)
40+
- Writer Xlsx ignoredErrors Before Drawings. [Issue #4200](https://github.com/PHPOffice/PhpSpreadsheet/issues/4200) [Issue #4145](https://github.com/PHPOffice/PhpSpreadsheet/issues/4145) [PR #4212](https://github.com/PHPOffice/PhpSpreadsheet/pull/4212)
4041
- Allow ANCHORARRAY as Data Validation list. [Issue #4197](https://github.com/PHPOffice/PhpSpreadsheet/issues/4197) [PR #4203](https://github.com/PHPOffice/PhpSpreadsheet/pull/4203)
4142

4243
## 2024-09-29 - 3.3.0 (no 3.0.\*, 3.1.\*, 3.2.\*)

src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ public function writeWorksheet(PhpspreadsheetWorksheet $worksheet, array $string
129129
// Breaks
130130
$this->writeBreaks($objWriter, $worksheet);
131131

132+
// IgnoredErrors
133+
$this->writeIgnoredErrors($objWriter);
134+
132135
// Drawings and/or Charts
133136
$this->writeDrawings($objWriter, $worksheet, $includeCharts);
134137

@@ -141,9 +144,6 @@ public function writeWorksheet(PhpspreadsheetWorksheet $worksheet, array $string
141144
// AlternateContent
142145
$this->writeAlternateContent($objWriter, $worksheet);
143146

144-
// IgnoredErrors
145-
$this->writeIgnoredErrors($objWriter);
146-
147147
// BackgroundImage must come after ignored, before table
148148
$this->writeBackgroundImage($objWriter, $worksheet);
149149

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpOffice\PhpSpreadsheetTests\Writer\Xlsx;
6+
7+
use PhpOffice\PhpSpreadsheet\Cell\DataType;
8+
use PhpOffice\PhpSpreadsheet\RichText\RichText;
9+
use PhpOffice\PhpSpreadsheet\Shared\File;
10+
use PhpOffice\PhpSpreadsheet\Spreadsheet;
11+
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
12+
use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter;
13+
use PHPUnit\Framework\TestCase;
14+
use ZipArchive;
15+
16+
class Issue4200Test extends TestCase
17+
{
18+
private string $outputFile = '';
19+
20+
protected function tearDown(): void
21+
{
22+
if ($this->outputFile !== '') {
23+
unlink($this->outputFile);
24+
$this->outputFile = '';
25+
}
26+
}
27+
28+
public function testIssue4200(): void
29+
{
30+
// ignoredErrors came after legacyDrawing
31+
$spreadsheet = new Spreadsheet();
32+
$sheet = $spreadsheet->getActiveSheet();
33+
$sheet->getCell('A1')->setValueExplicit('01', DataType::TYPE_STRING);
34+
$sheet->getCell('A1')
35+
->getIgnoredErrors()
36+
->setNumberStoredAsText(true);
37+
$richText = new RichText();
38+
$richText->createText('hello');
39+
$sheet->getComment('C1')
40+
->setText($richText);
41+
$writer = new XlsxWriter($spreadsheet);
42+
$this->outputFile = File::temporaryFilename();
43+
$writer->save($this->outputFile);
44+
$spreadsheet->disconnectWorksheets();
45+
46+
$zip = new ZipArchive();
47+
$open = $zip->open($this->outputFile, ZipArchive::RDONLY);
48+
if ($open !== true) {
49+
self::fail("zip open failed for {$this->outputFile}");
50+
} else {
51+
$contents = (string) $zip->getFromName('xl/worksheets/sheet1.xml');
52+
self::assertStringContainsString(
53+
'<ignoredErrors><ignoredError sqref="A1" numberStoredAsText="1"/></ignoredErrors><legacyDrawing r:id="rId_comments_vml1"/>',
54+
$contents
55+
);
56+
}
57+
}
58+
59+
public function testIssue4145(): void
60+
{
61+
// ignoredErrors came after drawing
62+
$spreadsheet = new Spreadsheet();
63+
$sheet = $spreadsheet->getActiveSheet();
64+
$sheet->getCell('A1')->setValueExplicit('01', DataType::TYPE_STRING);
65+
$sheet->getCell('A1')
66+
->getIgnoredErrors()
67+
->setNumberStoredAsText(true);
68+
$drawing = new Drawing();
69+
$drawing->setName('Blue Square');
70+
$drawing->setPath('tests/data/Writer/XLSX/blue_square.png');
71+
$drawing->setCoordinates('C1');
72+
$drawing->setWorksheet($sheet);
73+
$writer = new XlsxWriter($spreadsheet);
74+
$this->outputFile = File::temporaryFilename();
75+
$writer->save($this->outputFile);
76+
$spreadsheet->disconnectWorksheets();
77+
78+
$zip = new ZipArchive();
79+
$open = $zip->open($this->outputFile, ZipArchive::RDONLY);
80+
if ($open !== true) {
81+
self::fail("zip open failed for {$this->outputFile}");
82+
} else {
83+
$contents = (string) $zip->getFromName('xl/worksheets/sheet1.xml');
84+
self::assertStringContainsString(
85+
'<ignoredErrors><ignoredError sqref="A1" numberStoredAsText="1"/></ignoredErrors><drawing r:id="rId1"/>',
86+
$contents
87+
);
88+
}
89+
}
90+
}

0 commit comments

Comments
 (0)