Skip to content

Commit

Permalink
Support XML file without styles
Browse files Browse the repository at this point in the history
  • Loading branch information
PowerKiKi committed Jan 14, 2018
1 parent bf2dbba commit 481fc4a
Show file tree
Hide file tree
Showing 13 changed files with 280 additions and 189 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Support for shape style ending with `;` - [#304](https://github.com/PHPOffice/PhpSpreadsheet/issues/304)
- Freeze Panes takes wrong coordinates for XLSX - [#322](https://github.com/PHPOffice/PhpSpreadsheet/issues/322)
- `COLUMNS` and `ROWS` functions crashed in some cases - [#336](https://github.com/PHPOffice/PhpSpreadsheet/issues/336)
- Support XML file without styles - [#331](https://github.com/PHPOffice/PhpSpreadsheet/pull/331)

## [1.0.0] - 2017-12-25

Expand Down
381 changes: 219 additions & 162 deletions src/PhpSpreadsheet/Reader/Xml.php

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,10 @@
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Reader\BaseReader;
use PhpOffice\PhpSpreadsheet\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase;

class XEEValidatorTest extends TestCase
class XmlTest extends TestCase
{
/**
* @var Spreadsheet
*/
private $spreadsheetXEETest;

/**
* @return Spreadsheet
*/
protected function loadXEETestFile()
{
if (!$this->spreadsheetXEETest) {
$filename = '../samples/templates/Excel2003XMLTest.xml';

// Load into this instance
$reader = new Xml();
$this->spreadsheetXEETest = $reader->load($filename);
}

return $this->spreadsheetXEETest;
}

/**
* @dataProvider providerInvalidXML
* @expectedException \PhpOffice\PhpSpreadsheet\Reader\Exception
Expand All @@ -48,7 +26,7 @@ public function testInvalidXML($filename)
public function providerInvalidXML()
{
$tests = [];
foreach (glob(__DIR__ . '/../../data/Reader/XEE/XEETestInvalidUTF*.xml') as $file) {
foreach (glob(__DIR__ . '/../../data/Reader/Xml/XEETestInvalidUTF*.xml') as $file) {
$tests[basename($file)] = [realpath($file)];
}

Expand All @@ -70,7 +48,7 @@ public function testInvalidSimpleXML($filename)
public function providerInvalidSimpleXML()
{
$tests = [];
foreach (glob(__DIR__ . '/../../data/Reader/XEE/XEETestInvalidSimpleXML*.xml') as $file) {
foreach (glob(__DIR__ . '/../../data/Reader/Xml/XEETestInvalidSimpleXML*.xml') as $file) {
$tests[basename($file)] = [realpath($file)];
}

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

Expand All @@ -105,7 +83,8 @@ public function providerValidXML()
*/
public function testReadHyperlinks()
{
$spreadsheet = $this->loadXEETestFile();
$reader = new Xml();
$spreadsheet = $reader->load('../samples/templates/Excel2003XMLTest.xml');
$firstSheet = $spreadsheet->getSheet(0);

$hyperlink = $firstSheet->getCell('L1');
Expand All @@ -114,4 +93,11 @@ public function testReadHyperlinks()
self::assertEquals('PhpSpreadsheet', $hyperlink->getValue());
self::assertEquals('http://phpspreadsheet.readthedocs.io/', $hyperlink->getHyperlink()->getUrl());
}

public function testReadWithoutStyle()
{
$reader = new Xml();
$spreadsheet = $reader->load(__DIR__ . '/../../data/Reader/Xml/WithoutStyle.xml');
self::assertSame('Test String 1', $spreadsheet->getActiveSheet()->getCell('A1')->getValue());
}
}
47 changes: 47 additions & 0 deletions tests/data/Reader/Xml/WithoutStyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?><?mso-application progid="Excel.Sheet"?>
<Workbook xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:x="urn:schemas-microsoft-com:office:excel">
<OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
<Colors>
<Color>
<Index>3</Index>
<RGB>#000000</RGB>
</Color>
</Colors>
</OfficeDocumentSettings>
<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"/>
<Column ss:Span="1" ss:Width="48.3874"/>
<Column ss:Index="4" ss:Width="35.8866"/>
<Column ss:Span="6" ss:Width="48.3874"/>
<Column ss:Index="12" ss:Width="50.2583"/>
<Column ss:Span="1011" ss:Width="48.3874"/>
<Row ss:AutoFitHeight="0" ss:Height="14.9953">
<Cell>
<ss:Data xmlns="http://www.w3.org/TR/REC-html40" ss:Type="String">Test String 1</ss:Data>
<Comment>
<ss:Data xmlns="http://www.w3.org/TR/REC-html40">
<Font html:Face="Sans" html:Size="10">Test for a simple colour-formatted string</Font>
</ss:Data>
</Comment>
</Cell>
<Cell>
<Data ss:Type="Number">1</Data>
</Cell>
</Row>
</Table>
<x:WorksheetOptions/>
</ss:Worksheet>
</Workbook>
File renamed without changes.

0 comments on commit 481fc4a

Please sign in to comment.