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

Xmltest3 #1698

Merged
merged 2 commits into from
Dec 17, 2020
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
8 changes: 5 additions & 3 deletions src/PhpSpreadsheet/Reader/Xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -617,9 +617,11 @@ public function loadIntoExisting($pFilename, Spreadsheet $spreadsheet)
++$rowID;
}

$xmlX = $worksheet->children($namespaces['x']);
if (isset($xmlX->WorksheetOptions)) {
(new PageSettings($xmlX, $namespaces))->loadPageSettings($spreadsheet);
if (isset($namespaces['x'])) {
MarkBaker marked this conversation as resolved.
Show resolved Hide resolved
$xmlX = $worksheet->children($namespaces['x']);
if (isset($xmlX->WorksheetOptions)) {
(new PageSettings($xmlX, $namespaces))->loadPageSettings($spreadsheet);
}
}
}
++$worksheetID;
Expand Down
70 changes: 70 additions & 0 deletions tests/PhpSpreadsheetTests/Reader/Xml/XmlOddTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml;

use PhpOffice\PhpSpreadsheet\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Shared\File;
use PHPUnit\Framework\TestCase;

class XmlOddTest extends TestCase
{
private $filename = '';

protected function teardown(): void
{
if ($this->filename) {
unlink($this->filename);
$this->filename = '';
}
}

public function testWriteThenRead(): void
{
$xmldata = <<< 'EOT'
<?xml version="1.0" encoding="UTF-8"?><?mso-application progid="Excel.Sheet"?>
<Workbook xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet"
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
>
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
<Title>Xml2003 Short Workbook</Title>
</DocumentProperties>
<CustomDocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
<my_x05d0_Int dt:dt="integer">2</my_x05d0_Int>
</CustomDocumentProperties>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
<WindowHeight>9000</WindowHeight>
<WindowWidth>13860</WindowWidth>
<WindowTopX>240</WindowTopX>
<WindowTopY>75</WindowTopY>
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<ss:Worksheet ss:Name="Sample Data">
<Table>
<Column ss:Width="96.4913"/>
<Row ss:Index="8" ss:AutoFitHeight="0" ss:Height="14.9953">
<Cell>
<ss:Data ss:Type="String">Test String 1</ss:Data>
</Cell>
</Row>
</Table>
</ss:Worksheet>
</Workbook>
EOT;
$this->filename = tempnam(File::sysGetTempDir(), 'phpspreadsheet-test');
file_put_contents($this->filename, $xmldata);
$reader = new Xml();
$spreadsheet = $reader->load($this->filename);
self::assertEquals(1, $spreadsheet->getSheetCount());

$sheet = $spreadsheet->getActiveSheet();
self::assertEquals('Sample Data', $sheet->getTitle());
self::assertEquals('Test String 1', $sheet->getCell('A8')->getValue());

$props = $spreadsheet->getProperties();
self::assertEquals('Xml2003 Short Workbook', $props->getTitle());
self::assertEquals('2', $props->getCustomPropertyValue('myאInt'));
}
}