-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
read hyperlink for drawing image #490
Changes from 2 commits
ba9eb09
e85057b
5c3515a
7e95afa
bb83901
d0c5313
2d2e61c
98ead5b
5befe13
074018f
a4e6b7c
25a2121
ad89d0c
5bb7fb4
91a5de9
2100a90
35eb2fb
886ce8e
524db77
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
use PhpOffice\PhpSpreadsheet\IOFactory; | ||
|
||
require __DIR__ . '/../Header.php'; | ||
|
||
$inputFileType = 'Xlsx'; | ||
$inputFileName = __DIR__ . '/sampleData/example3.xlsx'; | ||
|
||
$helper->log('Loading file ' . pathinfo($inputFileName, PATHINFO_BASENAME) . ' information using IOFactory with a defined reader type of ' . $inputFileType); | ||
|
||
$reader = IOFactory::createReader($inputFileType); | ||
|
||
$spreadsheet = $reader->load($inputFileName); | ||
|
||
$helper->log('Set active sheet index 0'); | ||
$aSheet = $spreadsheet->setActiveSheetIndex(0); | ||
$drawings = $aSheet->getDrawingCollection(); | ||
/** @var $dr \PhpOffice\PhpSpreadsheet\Worksheet\Drawing */ | ||
foreach ($drawings as $dr) { | ||
$helper->log('links ' . $dr->getHyperlink()->getUrl()); | ||
} | ||
$helper->log('End'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
namespace PhpOffice\PhpSpreadsheet\Reader; | ||
|
||
use PhpOffice\PhpSpreadsheet\Cell\Coordinate; | ||
use PhpOffice\PhpSpreadsheet\Cell\Hyperlink; | ||
use PhpOffice\PhpSpreadsheet\Document\Properties; | ||
use PhpOffice\PhpSpreadsheet\NamedRange; | ||
use PhpOffice\PhpSpreadsheet\Reader\Xlsx\Chart; | ||
|
@@ -1546,9 +1547,12 @@ public function load($pFilename) | |
Settings::getLibXmlLoaderOptions() | ||
); | ||
$images = []; | ||
|
||
$hyperlinks = []; | ||
if ($relsDrawing && $relsDrawing->Relationship) { | ||
foreach ($relsDrawing->Relationship as $ele) { | ||
if ($ele['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink') { | ||
$hyperlinks[(string) $ele['Id']] = (string) $ele['Target']; | ||
} | ||
if ($ele['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image') { | ||
$images[(string) $ele['Id']] = self::dirAdd($fileDrawing, $ele['Target']); | ||
} elseif ($ele['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart') { | ||
|
@@ -1623,6 +1627,7 @@ public function load($pFilename) | |
$blip = $twoCellAnchor->pic->blipFill->children('http://schemas.openxmlformats.org/drawingml/2006/main')->blip; | ||
$xfrm = $twoCellAnchor->pic->spPr->children('http://schemas.openxmlformats.org/drawingml/2006/main')->xfrm; | ||
$outerShdw = $twoCellAnchor->pic->spPr->children('http://schemas.openxmlformats.org/drawingml/2006/main')->effectLst->outerShdw; | ||
$hlinkClick = $twoCellAnchor->pic->nvPicPr->cNvPr->children('http://schemas.openxmlformats.org/drawingml/2006/main')->hlinkClick; | ||
$objDrawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing(); | ||
$objDrawing->setName((string) self::getArrayItem($twoCellAnchor->pic->nvPicPr->cNvPr->attributes(), 'name')); | ||
$objDrawing->setDescription((string) self::getArrayItem($twoCellAnchor->pic->nvPicPr->cNvPr->attributes(), 'descr')); | ||
|
@@ -1654,6 +1659,14 @@ public function load($pFilename) | |
$shadow->getColor()->setRGB(self::getArrayItem($outerShdw->srgbClr->attributes(), 'val')); | ||
$shadow->setAlpha(self::getArrayItem($outerShdw->srgbClr->alpha->attributes(), 'val') / 1000); | ||
} | ||
if ($hlinkClick) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idem, extract to method. |
||
$hlinkId = (string) $hlinkClick->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships')['id']; | ||
$hyperlink = new Hyperlink( | ||
$hyperlinks[$hlinkId], | ||
(string) self::getArrayItem($twoCellAnchor->pic->nvPicPr->cNvPr->attributes(), 'name') | ||
); | ||
$objDrawing->setHyperlink($hyperlink); | ||
} | ||
$objDrawing->setWorksheet($docSheet); | ||
} elseif (($this->includeCharts) && ($twoCellAnchor->graphicFrame)) { | ||
$fromCoordinate = Coordinate::stringFromColumnIndex(((string) $twoCellAnchor->from->col) + 1) . ($twoCellAnchor->from->row + 1); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
namespace PhpOffice\PhpSpreadsheet\Worksheet; | ||
|
||
use PhpOffice\PhpSpreadsheet\Cell\Hyperlink; | ||
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; | ||
use PhpOffice\PhpSpreadsheet\IComparable; | ||
|
||
|
@@ -98,6 +99,13 @@ class BaseDrawing implements IComparable | |
*/ | ||
protected $shadow; | ||
|
||
/** | ||
* Image hyperlink. | ||
* | ||
* @var Hyperlink | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be |
||
*/ | ||
protected $hyperlink; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be private |
||
|
||
/** | ||
* Create a new BaseDrawing. | ||
*/ | ||
|
@@ -508,4 +516,24 @@ public function __clone() | |
} | ||
} | ||
} | ||
|
||
/** | ||
* @param Hyperlink $pHyperlink | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be |
||
*/ | ||
public function setHyperlink(Hyperlink $pHyperlink = null) | ||
{ | ||
$this->hyperlink = $pHyperlink; | ||
} | ||
|
||
/** | ||
* @return Hyperlink | ||
*/ | ||
public function getHyperlink() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing comment with return type |
||
{ | ||
if ($this->hyperlink === null) { | ||
$this->hyperlink = new Hyperlink(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you create new Hyperlink if it does not exist, instead of returning |
||
} | ||
|
||
return $this->hyperlink; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We try to avoid adding XLSX files when possible to avoid growing the size of the repository. So please delete
samples/Reader/sampleData/example3.xlsx
, and either change the sample to write and read, or delete the sample entirely (but do not keep it with only read).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has not been addressed.