Skip to content

Commit

Permalink
Support for read Hyperlink for xml
Browse files Browse the repository at this point in the history
added unit test and change log
  • Loading branch information
yasar-luo committed Sep 20, 2017
1 parent 3a6f7ed commit 8f8bbba
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added

- Support for chart fill color - @CrazyBite [#158](https://github.com/PHPOffice/PhpSpreadsheet/pull/158)
- Support for read Hyperlink for xml - [@GreatHumorist](https://github.com/GreatHumorist) [#223](https://github.com/PHPOffice/PhpSpreadsheet/pull/223)

### Changed

Expand Down
4 changes: 3 additions & 1 deletion samples/templates/Excel2003XMLTest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,9 @@
<Data ss:Type="String">AE</Data>
</Cell>
<Cell ss:StyleID="ce5"/>
<Cell ss:StyleID="ce5"/>
<Cell ss:StyleID="ce5" ss:HRef="http://www.phpexcel.net/">
<Data ss:Type="String">PHPExcel</Data>
</Cell>
<Cell ss:StyleID="ce5"/>
<Cell ss:StyleID="ce5"/>
<Cell ss:StyleID="ce5"/>
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Reader/Xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ public function loadIntoExisting($pFilename, Spreadsheet $spreadsheet)
if (isset($cell_ss['HRef'])) {
$spreadsheet->getActiveSheet()->getCell($cellRange)->getHyperlink()->setUrl($cell_ss['HRef']);
}

if ((isset($cell_ss['MergeAcross'])) || (isset($cell_ss['MergeDown']))) {
$columnTo = $columnID;
if (isset($cell_ss['MergeAcross'])) {
Expand Down
39 changes: 39 additions & 0 deletions tests/PhpSpreadsheetTests/Reader/XEEValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,35 @@

namespace PhpOffice\PhpSpreadsheetTests\Reader;

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 PHPUnit_Framework_TestCase
{
/**
* @var Spreadsheet
*/
private $spreadsheetXEETest;

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

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

return $this->spreadsheetXEETest;
}

/**
* @dataProvider providerInvalidXML
* @expectedException \PhpOffice\PhpSpreadsheet\Reader\Exception
Expand Down Expand Up @@ -53,4 +77,19 @@ public function providerValidXML()

return $tests;
}

/**
* Check if it can read XML Hyperlink correctly.
*/
public function testReadHyperlinks()
{
$spreadsheet = $this->loadXEETestFile();
$firstSheet = $spreadsheet->getSheet(0);

$hyperlink = $firstSheet->getCell('L1');

$this->assertEquals(DataType::TYPE_STRING, $hyperlink->getDataType());
$this->assertEquals('PHPExcel', $hyperlink->getValue());
$this->assertEquals('http://www.phpexcel.net/', $hyperlink->getHyperlink()->getUrl());
}
}

0 comments on commit 8f8bbba

Please sign in to comment.