Skip to content

Commit 89c5897

Browse files
PowerKiKiFrederic Delaunay
authored and
Frederic Delaunay
committed
Support XML file without styles
Closes PHPOffice#331 Closes PHPOffice/PHPExcel#559 Fixes PHPOffice/PHPExcel#558
1 parent 08c0139 commit 89c5897

13 files changed

+280
-189
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1818
- Support for shape style ending with `;` - [#304](https://github.com/PHPOffice/PhpSpreadsheet/issues/304)
1919
- Freeze Panes takes wrong coordinates for XLSX - [#322](https://github.com/PHPOffice/PhpSpreadsheet/issues/322)
2020
- `COLUMNS` and `ROWS` functions crashed in some cases - [#336](https://github.com/PHPOffice/PhpSpreadsheet/issues/336)
21+
- Support XML file without styles - [#331](https://github.com/PHPOffice/PhpSpreadsheet/pull/331)
2122

2223
## [1.0.0] - 2017-12-25
2324

src/PhpSpreadsheet/Reader/Xml.php

+219-162
Large diffs are not rendered by default.

tests/PhpSpreadsheetTests/Reader/XEEValidatorTest.php renamed to tests/PhpSpreadsheetTests/Reader/XmlTest.php

+13-27
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,10 @@
55
use PhpOffice\PhpSpreadsheet\Cell\DataType;
66
use PhpOffice\PhpSpreadsheet\Reader\BaseReader;
77
use PhpOffice\PhpSpreadsheet\Reader\Xml;
8-
use PhpOffice\PhpSpreadsheet\Spreadsheet;
98
use PHPUnit\Framework\TestCase;
109

11-
class XEEValidatorTest extends TestCase
10+
class XmlTest extends TestCase
1211
{
13-
/**
14-
* @var Spreadsheet
15-
*/
16-
private $spreadsheetXEETest;
17-
18-
/**
19-
* @return Spreadsheet
20-
*/
21-
protected function loadXEETestFile()
22-
{
23-
if (!$this->spreadsheetXEETest) {
24-
$filename = '../samples/templates/Excel2003XMLTest.xml';
25-
26-
// Load into this instance
27-
$reader = new Xml();
28-
$this->spreadsheetXEETest = $reader->load($filename);
29-
}
30-
31-
return $this->spreadsheetXEETest;
32-
}
33-
3412
/**
3513
* @dataProvider providerInvalidXML
3614
* @expectedException \PhpOffice\PhpSpreadsheet\Reader\Exception
@@ -48,7 +26,7 @@ public function testInvalidXML($filename)
4826
public function providerInvalidXML()
4927
{
5028
$tests = [];
51-
foreach (glob(__DIR__ . '/../../data/Reader/XEE/XEETestInvalidUTF*.xml') as $file) {
29+
foreach (glob(__DIR__ . '/../../data/Reader/Xml/XEETestInvalidUTF*.xml') as $file) {
5230
$tests[basename($file)] = [realpath($file)];
5331
}
5432

@@ -70,7 +48,7 @@ public function testInvalidSimpleXML($filename)
7048
public function providerInvalidSimpleXML()
7149
{
7250
$tests = [];
73-
foreach (glob(__DIR__ . '/../../data/Reader/XEE/XEETestInvalidSimpleXML*.xml') as $file) {
51+
foreach (glob(__DIR__ . '/../../data/Reader/Xml/XEETestInvalidSimpleXML*.xml') as $file) {
7452
$tests[basename($file)] = [realpath($file)];
7553
}
7654

@@ -93,7 +71,7 @@ public function testValidXML($filename, $expectedResult)
9371
public function providerValidXML()
9472
{
9573
$tests = [];
96-
foreach (glob(__DIR__ . '/../../data/Reader/XEE/XEETestValid*.xml') as $file) {
74+
foreach (glob(__DIR__ . '/../../data/Reader/Xml/XEETestValid*.xml') as $file) {
9775
$tests[basename($file)] = [realpath($file), file_get_contents($file)];
9876
}
9977

@@ -105,7 +83,8 @@ public function providerValidXML()
10583
*/
10684
public function testReadHyperlinks()
10785
{
108-
$spreadsheet = $this->loadXEETestFile();
86+
$reader = new Xml();
87+
$spreadsheet = $reader->load('../samples/templates/Excel2003XMLTest.xml');
10988
$firstSheet = $spreadsheet->getSheet(0);
11089

11190
$hyperlink = $firstSheet->getCell('L1');
@@ -114,4 +93,11 @@ public function testReadHyperlinks()
11493
self::assertEquals('PhpSpreadsheet', $hyperlink->getValue());
11594
self::assertEquals('http://phpspreadsheet.readthedocs.io/', $hyperlink->getHyperlink()->getUrl());
11695
}
96+
97+
public function testReadWithoutStyle()
98+
{
99+
$reader = new Xml();
100+
$spreadsheet = $reader->load(__DIR__ . '/../../data/Reader/Xml/WithoutStyle.xml');
101+
self::assertSame('Test String 1', $spreadsheet->getActiveSheet()->getCell('A1')->getValue());
102+
}
117103
}
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0" encoding="UTF-8"?><?mso-application progid="Excel.Sheet"?>
2+
<Workbook xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40"
3+
xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns="urn:schemas-microsoft-com:office:spreadsheet"
5+
xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml"
6+
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:x="urn:schemas-microsoft-com:office:excel">
7+
<OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
8+
<Colors>
9+
<Color>
10+
<Index>3</Index>
11+
<RGB>#000000</RGB>
12+
</Color>
13+
</Colors>
14+
</OfficeDocumentSettings>
15+
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
16+
<WindowHeight>9000</WindowHeight>
17+
<WindowWidth>13860</WindowWidth>
18+
<WindowTopX>240</WindowTopX>
19+
<WindowTopY>75</WindowTopY>
20+
<ProtectStructure>False</ProtectStructure>
21+
<ProtectWindows>False</ProtectWindows>
22+
</ExcelWorkbook>
23+
<ss:Worksheet ss:Name="Sample Data">
24+
<Table>
25+
<Column ss:Width="96.4913"/>
26+
<Column ss:Span="1" ss:Width="48.3874"/>
27+
<Column ss:Index="4" ss:Width="35.8866"/>
28+
<Column ss:Span="6" ss:Width="48.3874"/>
29+
<Column ss:Index="12" ss:Width="50.2583"/>
30+
<Column ss:Span="1011" ss:Width="48.3874"/>
31+
<Row ss:AutoFitHeight="0" ss:Height="14.9953">
32+
<Cell>
33+
<ss:Data xmlns="http://www.w3.org/TR/REC-html40" ss:Type="String">Test String 1</ss:Data>
34+
<Comment>
35+
<ss:Data xmlns="http://www.w3.org/TR/REC-html40">
36+
<Font html:Face="Sans" html:Size="10">Test for a simple colour-formatted string</Font>
37+
</ss:Data>
38+
</Comment>
39+
</Cell>
40+
<Cell>
41+
<Data ss:Type="Number">1</Data>
42+
</Cell>
43+
</Row>
44+
</Table>
45+
<x:WorksheetOptions/>
46+
</ss:Worksheet>
47+
</Workbook>

0 commit comments

Comments
 (0)