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

Added xml reader hyperlink support #223

Closed
wants to merge 9 commits into from
Closed
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
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: 2 additions & 2 deletions docs/references/features-cross-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@
<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: red;"></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>
Expand Down Expand Up @@ -1496,4 +1496,4 @@
</table>

1. Only BIFF8 files support Rich Text. Prior to that, comments could only be plain text
2. Only BIFF8 files support alignment and rotation. Prior to that, comments could only be unformatted text
2. Only BIFF8 files support alignment and rotation. Prior to that, comments could only be unformatted text
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://phpspreadsheet.readthedocs.io/">
<Data ss:Type="String">PhpSpreadsheet</Data>
</Cell>
<Cell ss:StyleID="ce5"/>
<Cell ss:StyleID="ce5"/>
<Cell ss:StyleID="ce5"/>
Expand Down
4 changes: 4 additions & 0 deletions src/PhpSpreadsheet/Reader/Xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,10 @@ 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 = '../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 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('PhpSpreadsheet', $hyperlink->getValue());
$this->assertEquals('http://phpspreadsheet.readthedocs.io/', $hyperlink->getHyperlink()->getUrl());
}
}