Skip to content

Commit

Permalink
Merge pull request #4212 from oleibman/issue4200
Browse files Browse the repository at this point in the history
Write ignoredErrors Tag Before Drawings
  • Loading branch information
oleibman authored Nov 5, 2024
2 parents ce32cba + aba2385 commit 915bfc5
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
- 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)
- Invalid Html Due to Cached Filesize. [Issue #1107](https://github.com/PHPOffice/PhpSpreadsheet/issues/1107) [PR #4184](https://github.com/PHPOffice/PhpSpreadsheet/pull/4184)
- Excel 2003 Allows Html Entities. [Issue #2157](https://github.com/PHPOffice/PhpSpreadsheet/issues/2157) [PR #4187](https://github.com/PHPOffice/PhpSpreadsheet/pull/4187)
- 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)
- Allow ANCHORARRAY as Data Validation list. [Issue #4197](https://github.com/PHPOffice/PhpSpreadsheet/issues/4197) [PR #4203](https://github.com/PHPOffice/PhpSpreadsheet/pull/4203)

## 2024-09-29 - 3.3.0 (no 3.0.\*, 3.1.\*, 3.2.\*)
Expand Down
6 changes: 3 additions & 3 deletions src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ public function writeWorksheet(PhpspreadsheetWorksheet $worksheet, array $string
// Breaks
$this->writeBreaks($objWriter, $worksheet);

// IgnoredErrors
$this->writeIgnoredErrors($objWriter);

// Drawings and/or Charts
$this->writeDrawings($objWriter, $worksheet, $includeCharts);

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

// IgnoredErrors
$this->writeIgnoredErrors($objWriter);

// BackgroundImage must come after ignored, before table
$this->writeBackgroundImage($objWriter, $worksheet);

Expand Down
90 changes: 90 additions & 0 deletions tests/PhpSpreadsheetTests/Writer/Xlsx/Issue4200Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

declare(strict_types=1);

namespace PhpOffice\PhpSpreadsheetTests\Writer\Xlsx;

use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\RichText\RichText;
use PhpOffice\PhpSpreadsheet\Shared\File;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter;
use PHPUnit\Framework\TestCase;
use ZipArchive;

class Issue4200Test extends TestCase
{
private string $outputFile = '';

protected function tearDown(): void
{
if ($this->outputFile !== '') {
unlink($this->outputFile);
$this->outputFile = '';
}
}

public function testIssue4200(): void
{
// ignoredErrors came after legacyDrawing
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->getCell('A1')->setValueExplicit('01', DataType::TYPE_STRING);
$sheet->getCell('A1')
->getIgnoredErrors()
->setNumberStoredAsText(true);
$richText = new RichText();
$richText->createText('hello');
$sheet->getComment('C1')
->setText($richText);
$writer = new XlsxWriter($spreadsheet);
$this->outputFile = File::temporaryFilename();
$writer->save($this->outputFile);
$spreadsheet->disconnectWorksheets();

$zip = new ZipArchive();
$open = $zip->open($this->outputFile, ZipArchive::RDONLY);
if ($open !== true) {
self::fail("zip open failed for {$this->outputFile}");
} else {
$contents = (string) $zip->getFromName('xl/worksheets/sheet1.xml');
self::assertStringContainsString(
'<ignoredErrors><ignoredError sqref="A1" numberStoredAsText="1"/></ignoredErrors><legacyDrawing r:id="rId_comments_vml1"/>',
$contents
);
}
}

public function testIssue4145(): void
{
// ignoredErrors came after drawing
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->getCell('A1')->setValueExplicit('01', DataType::TYPE_STRING);
$sheet->getCell('A1')
->getIgnoredErrors()
->setNumberStoredAsText(true);
$drawing = new Drawing();
$drawing->setName('Blue Square');
$drawing->setPath('tests/data/Writer/XLSX/blue_square.png');
$drawing->setCoordinates('C1');
$drawing->setWorksheet($sheet);
$writer = new XlsxWriter($spreadsheet);
$this->outputFile = File::temporaryFilename();
$writer->save($this->outputFile);
$spreadsheet->disconnectWorksheets();

$zip = new ZipArchive();
$open = $zip->open($this->outputFile, ZipArchive::RDONLY);
if ($open !== true) {
self::fail("zip open failed for {$this->outputFile}");
} else {
$contents = (string) $zip->getFromName('xl/worksheets/sheet1.xml');
self::assertStringContainsString(
'<ignoredErrors><ignoredError sqref="A1" numberStoredAsText="1"/></ignoredErrors><drawing r:id="rId1"/>',
$contents
);
}
}
}

0 comments on commit 915bfc5

Please sign in to comment.