Added xml reader hyperlink support

Closes #223
This commit is contained in:
GreatHumorist 2017-09-18 16:03:32 +08:00 committed by Adrien Crivelli
parent aef4d711f5
commit 7aa6233185
No known key found for this signature in database
GPG Key ID: B182FD79DC6DE92E
5 changed files with 48 additions and 4 deletions

View File

@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added ### Added
- Support for chart fill color - @CrazyBite [#158](https://github.com/PHPOffice/PhpSpreadsheet/pull/158) - 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 ### Changed

View File

@ -1167,7 +1167,7 @@
<td style="padding-left: 1em;">Hyperlinks</td> <td style="padding-left: 1em;">Hyperlinks</td>
<td style="text-align: center; color: green;"></td> <td style="text-align: center; color: green;"></td>
<td style="text-align: center; color: green;"></td> <td style="text-align: center; color: green;"></td>
<td style="text-align: center; color: red;"></td> <td style="text-align: center; color: green;"></td>
<td style="text-align: center; color: green;"></td> <td style="text-align: center; color: green;"></td>
<td style="text-align: center; color: red;"></td> <td style="text-align: center; color: red;"></td>
<td style="text-align: center; color: red;"></td> <td style="text-align: center; color: red;"></td>

View File

@ -549,7 +549,9 @@
<Data ss:Type="String">AE</Data> <Data ss:Type="String">AE</Data>
</Cell> </Cell>
<Cell ss:StyleID="ce5"/> <Cell ss:StyleID="ce5"/>
<Cell ss:StyleID="ce5"/> <Cell ss:StyleID="ce5" ss:HRef="http://phpspreadsheet.readthedocs.io/">
<Data ss:Type="String">PhpSpreadsheet</Data>
</Cell>
<Cell ss:StyleID="ce5"/> <Cell ss:StyleID="ce5"/>
<Cell ss:StyleID="ce5"/> <Cell ss:StyleID="ce5"/>
<Cell ss:StyleID="ce5"/> <Cell ss:StyleID="ce5"/>

View File

@ -610,6 +610,10 @@ class Xml extends BaseReader implements IReader
} }
} }
if (isset($cell_ss['HRef'])) {
$spreadsheet->getActiveSheet()->getCell($cellRange)->getHyperlink()->setUrl($cell_ss['HRef']);
}
if ((isset($cell_ss['MergeAcross'])) || (isset($cell_ss['MergeDown']))) { if ((isset($cell_ss['MergeAcross'])) || (isset($cell_ss['MergeDown']))) {
$columnTo = $columnID; $columnTo = $columnID;
if (isset($cell_ss['MergeAcross'])) { if (isset($cell_ss['MergeAcross'])) {

View File

@ -2,13 +2,35 @@
namespace PhpOffice\PhpSpreadsheetTests\Reader; namespace PhpOffice\PhpSpreadsheetTests\Reader;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Reader\BaseReader; use PhpOffice\PhpSpreadsheet\Reader\BaseReader;
use PhpOffice\PhpSpreadsheet\Reader\Exception;
use PhpOffice\PhpSpreadsheet\Reader\Xml; use PhpOffice\PhpSpreadsheet\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit_Framework_TestCase; use PHPUnit_Framework_TestCase;
class XEEValidatorTest extends PHPUnit_Framework_TestCase class XEEValidatorTest extends PHPUnit_Framework_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 * @dataProvider providerInvalidXML
* @expectedException \PhpOffice\PhpSpreadsheet\Reader\Exception * @expectedException \PhpOffice\PhpSpreadsheet\Reader\Exception
@ -77,4 +99,19 @@ class XEEValidatorTest extends PHPUnit_Framework_TestCase
return $tests; return $tests;
} }
/**
* Check if it can read XML Hyperlink correctly.
*/
public function testReadHyperlinks()
{
$spreadsheet = $this->loadXEETestFile();
$firstSheet = $spreadsheet->getSheet(0);
$hyperlink = $firstSheet->getCell('L1');
self::assertEquals(DataType::TYPE_STRING, $hyperlink->getDataType());
self::assertEquals('PhpSpreadsheet', $hyperlink->getValue());
self::assertEquals('http://phpspreadsheet.readthedocs.io/', $hyperlink->getHyperlink()->getUrl());
}
} }