Added Hyperlink Support

Adaptation of a previous version PR https://github.com/box/spout/pull/352
This commit is contained in:
97WaterPolo 2019-06-28 12:41:09 -04:00 committed by GitHub
parent 6c4086cf97
commit e087e2b03e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -213,7 +213,20 @@ EOD;
$cellXML .= ' s="' . $styleId . '"';
if ($cell->isString()) {
$cellXML .= $this->getCellXMLFragmentForNonEmptyString($cell->getValue());
$matches = array();
if (preg_match('/=HYPERLINK\([\'"](.*)[\'"],\s*[\'"](.*)[\'"]\)/', $cell->getValue(), $matches)) {
if ($this->stringHelper->getStringLength($cell->getValue()) > self::MAX_CHARACTERS_PER_CELL) {
throw new InvalidArgumentException('Trying to add a value that exceeds the maximum number of characters allowed in a cell (32,767)');
}
// Special case to add HYPERLINK Formula
$url = $this->stringsEscaper->escape($matches[1]);
$text = $this->stringsEscaper->escape($matches[2]);
$formula = sprintf('HYPERLINK("%s","%s")', $url, $text);
$cellXML = sprintf(
'<c r="%s%s" t="str"><f>%s</f><v>%s</v></c>',
$columnIndex, $rowIndex, $formula, $text);
}else
$cellXML .= $this->getCellXMLFragmentForNonEmptyString($cell->getValue());
} elseif ($cell->isBoolean()) {
$cellXML .= ' t="b"><v>' . (int) ($cell->getValue()) . '</v></c>';
} elseif ($cell->isNumeric()) {