-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correct Xlsx Parsing of quotePrefix="0" (#3438)
* Correct Xlsx Parsing of quotePrefix="0" Fix #3435. Mis-parsed attribute is not normally generated by Excel or PhpSpreadsheet, but some 3rd-party software (correctly) generates it. * Update Issue3435Test.php
- Loading branch information
Showing
3 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx; | ||
|
||
use PhpOffice\PhpSpreadsheet\Reader\Xlsx; | ||
|
||
class Issue3435Test extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private static $testbook = 'tests/data/Reader/XLSX/issue.3435.xlsx'; | ||
|
||
public function testPreliminaries(): void | ||
{ | ||
$file = 'zip://'; | ||
$file .= self::$testbook; | ||
$file .= '#xl/styles.xml'; | ||
$data = file_get_contents($file); | ||
// confirm that file contains expected namespaced xml tag | ||
if ($data === false) { | ||
self::fail('Unable to read file'); | ||
} else { | ||
$expected = <<<EOF | ||
<xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/> | ||
<xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0" quotePrefix="1"/> | ||
<xf numFmtId="0" fontId="1" fillId="2" borderId="1" xfId="0" quotePrefix="0" applyFont="1" applyFill="1" applyBorder="1"/> | ||
EOF; | ||
self::assertStringContainsString($expected, $data); | ||
} | ||
} | ||
|
||
public function testQuotePrefix(): void | ||
{ | ||
// Parsing of quotePrefix="0" was incorrect, now corrected. | ||
$reader = new Xlsx(); | ||
$spreadsheet = $reader->load(self::$testbook); | ||
$sheet = $spreadsheet->getActiveSheet(); | ||
self::assertTrue($sheet->getStyle('A1')->getQuotePrefix()); | ||
self::assertFalse($sheet->getStyle('A2')->getQuotePrefix()); | ||
self::assertFalse($sheet->getStyle('A3')->getQuotePrefix()); | ||
$spreadsheet->disconnectWorksheets(); | ||
} | ||
} |
Binary file not shown.