|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx; |
| 4 | + |
| 5 | +use PhpOffice\PhpSpreadsheet\Reader\Xlsx; |
| 6 | + |
| 7 | +class Issue3495Test extends \PHPUnit\Framework\TestCase |
| 8 | +{ |
| 9 | + /** |
| 10 | + * @var string |
| 11 | + */ |
| 12 | + private static $testbook = 'tests/data/Reader/XLSX/issue.3495d.xlsx'; |
| 13 | + |
| 14 | + public function testPreliminaries(): void |
| 15 | + { |
| 16 | + $file = 'zip://'; |
| 17 | + $file .= self::$testbook; |
| 18 | + $file2 = $file; |
| 19 | + $file .= '#xl/styles.xml'; |
| 20 | + $file2 .= '#xl/worksheets/sheet1.xml'; |
| 21 | + $data = file_get_contents($file); |
| 22 | + if ($data === false) { |
| 23 | + self::fail('Unable to read file'); |
| 24 | + } else { |
| 25 | + // default style plus one other style |
| 26 | + self::assertStringContainsString( |
| 27 | + '<cellXfs count="2">' |
| 28 | + . '<xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/>' |
| 29 | + . '<xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0" quotePrefix="1"/>', |
| 30 | + $data |
| 31 | + ); |
| 32 | + } |
| 33 | + $data = file_get_contents($file2); |
| 34 | + if ($data === false) { |
| 35 | + self::fail('Unable to read file'); |
| 36 | + } else { |
| 37 | + // cells B1, C1, D1 all nominally use quotePrefix s="1" |
| 38 | + self::assertStringContainsString('<c r="B1" s="1">', $data); |
| 39 | + self::assertStringContainsString('<c r="C1" s="1" t="s">', $data); |
| 40 | + self::assertStringContainsString('<c r="D1" s="1" t="s">', $data); |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + public function testFormulaDespiteQuotePrefix(): void |
| 45 | + { |
| 46 | + $reader = new Xlsx(); |
| 47 | + $spreadsheet = $reader->load(self::$testbook); |
| 48 | + $sheet = $spreadsheet->getActiveSheet(); |
| 49 | + self::assertSame('=2+3', $sheet->getCell('B1')->getValue()); |
| 50 | + self::assertSame('=1+2', $sheet->getCell('C1')->getValue()); |
| 51 | + self::assertSame('3', $sheet->getCell('D1')->getValue()); |
| 52 | + self::assertSame(5, $sheet->getCell('B1')->getCalculatedValue()); |
| 53 | + self::assertSame('=1+2', $sheet->getCell('C1')->getCalculatedValue()); |
| 54 | + self::assertSame('3', $sheet->getCell('D1')->getCalculatedValue()); |
| 55 | + $spreadsheet->disconnectWorksheets(); |
| 56 | + } |
| 57 | +} |
0 commit comments