Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct Xlsx Parsing of quotePrefix="0" #3438

Merged
merged 3 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Reader/Xlsx.php
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet
$numFmt = NumberFormat::builtInFormatCode((int) $xf['numFmtId']);
}
}
$quotePrefix = (bool) ($xf['quotePrefix'] ?? false);
$quotePrefix = (bool) (string) ($xf['quotePrefix'] ?? '');

$style = (object) [
'numFmt' => $numFmt ?? NumberFormat::FORMAT_GENERAL,
Expand Down Expand Up @@ -653,7 +653,7 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet
}
}

$quotePrefix = (bool) ($xf['quotePrefix'] ?? false);
$quotePrefix = (bool) (string) ($xf['quotePrefix'] ?? '');

$cellStyle = (object) [
'numFmt' => $numFmt,
Expand Down
44 changes: 44 additions & 0 deletions tests/PhpSpreadsheetTests/Reader/Xlsx/Issue3435Test.php
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 added tests/data/Reader/XLSX/issue.3435.xlsx
Binary file not shown.