Skip to content

Commit 3025824

Browse files
authored
Merge pull request #1698
* Merge pull request #4 from PHPOffice/master * Restore Omitted Read XML Test
1 parent 8833c23 commit 3025824

File tree

2 files changed

+75
-3
lines changed

2 files changed

+75
-3
lines changed

src/PhpSpreadsheet/Reader/Xml.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -617,9 +617,11 @@ public function loadIntoExisting($pFilename, Spreadsheet $spreadsheet)
617617
++$rowID;
618618
}
619619

620-
$xmlX = $worksheet->children($namespaces['x']);
621-
if (isset($xmlX->WorksheetOptions)) {
622-
(new PageSettings($xmlX, $namespaces))->loadPageSettings($spreadsheet);
620+
if (isset($namespaces['x'])) {
621+
$xmlX = $worksheet->children($namespaces['x']);
622+
if (isset($xmlX->WorksheetOptions)) {
623+
(new PageSettings($xmlX, $namespaces))->loadPageSettings($spreadsheet);
624+
}
623625
}
624626
}
625627
++$worksheetID;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml;
4+
5+
use PhpOffice\PhpSpreadsheet\Reader\Xml;
6+
use PhpOffice\PhpSpreadsheet\Shared\File;
7+
use PHPUnit\Framework\TestCase;
8+
9+
class XmlOddTest extends TestCase
10+
{
11+
private $filename = '';
12+
13+
protected function teardown(): void
14+
{
15+
if ($this->filename) {
16+
unlink($this->filename);
17+
$this->filename = '';
18+
}
19+
}
20+
21+
public function testWriteThenRead(): void
22+
{
23+
$xmldata = <<< 'EOT'
24+
<?xml version="1.0" encoding="UTF-8"?><?mso-application progid="Excel.Sheet"?>
25+
<Workbook xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet"
26+
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
27+
xmlns="urn:schemas-microsoft-com:office:spreadsheet"
28+
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
29+
>
30+
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
31+
<Title>Xml2003 Short Workbook</Title>
32+
</DocumentProperties>
33+
<CustomDocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
34+
<my_x05d0_Int dt:dt="integer">2</my_x05d0_Int>
35+
</CustomDocumentProperties>
36+
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
37+
<WindowHeight>9000</WindowHeight>
38+
<WindowWidth>13860</WindowWidth>
39+
<WindowTopX>240</WindowTopX>
40+
<WindowTopY>75</WindowTopY>
41+
<ProtectStructure>False</ProtectStructure>
42+
<ProtectWindows>False</ProtectWindows>
43+
</ExcelWorkbook>
44+
<ss:Worksheet ss:Name="Sample Data">
45+
<Table>
46+
<Column ss:Width="96.4913"/>
47+
<Row ss:Index="8" ss:AutoFitHeight="0" ss:Height="14.9953">
48+
<Cell>
49+
<ss:Data ss:Type="String">Test String 1</ss:Data>
50+
</Cell>
51+
</Row>
52+
</Table>
53+
</ss:Worksheet>
54+
</Workbook>
55+
EOT;
56+
$this->filename = tempnam(File::sysGetTempDir(), 'phpspreadsheet-test');
57+
file_put_contents($this->filename, $xmldata);
58+
$reader = new Xml();
59+
$spreadsheet = $reader->load($this->filename);
60+
self::assertEquals(1, $spreadsheet->getSheetCount());
61+
62+
$sheet = $spreadsheet->getActiveSheet();
63+
self::assertEquals('Sample Data', $sheet->getTitle());
64+
self::assertEquals('Test String 1', $sheet->getCell('A8')->getValue());
65+
66+
$props = $spreadsheet->getProperties();
67+
self::assertEquals('Xml2003 Short Workbook', $props->getTitle());
68+
self::assertEquals('2', $props->getCustomPropertyValue('myאInt'));
69+
}
70+
}

0 commit comments

Comments
 (0)