Ignore square-$-brackets prefix in format string (#2886)
* Ignore square-$-brackets prefix in format string * Test for square-$-brackets prefix in format string issue fixed * Fix for phpstan compliance * Additional assert for checking number format of tested source cell
This commit is contained in:
parent
11348a4830
commit
1829dea91e
|
|
@ -112,6 +112,9 @@ class Formatter
|
|||
return $value;
|
||||
}
|
||||
|
||||
// Ignore square-$-brackets prefix in format string, like "[$-411]ge.m.d", "[$-010419]0%", etc
|
||||
$format = (string) preg_replace('/^\[\$-[^\]]*\]/', '', $format);
|
||||
|
||||
$format = (string) preg_replace_callback(
|
||||
'/(["])(?:(?=(\\\\?))\\2.)*?\\1/u',
|
||||
function ($matches) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class Issue2885Test extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private static $testbook = 'tests/data/Reader/XLSX/issue.2885.xlsx';
|
||||
|
||||
public function testIssue2885(): void
|
||||
{
|
||||
$filename = self::$testbook;
|
||||
$reader = new Xlsx();
|
||||
$spreadsheet = $reader->load($filename);
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
self::assertSame('[$-809]0%', $sheet->getStyle('A1')->getNumberFormat()->getFormatCode());
|
||||
|
||||
$finishColumns = $sheet->getHighestColumn();
|
||||
$rowsCount = $sheet->getHighestRow();
|
||||
$rows = $sheet->rangeToArray("A1:{$finishColumns}{$rowsCount}");
|
||||
self::assertSame('8%', $rows[0][0]);
|
||||
|
||||
$spreadsheet->disconnectWorksheets();
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Loading…
Reference in New Issue