Skip to content
This repository was archived by the owner on May 26, 2022. It is now read-only.
Closed
Changes from 1 commit
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
19 changes: 15 additions & 4 deletions src/Spout/Writer/XLSX/Internal/Worksheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,22 @@ private function getCellXML($rowIndex, $cellNumber, $cellValue, $styleId)
$cellXML .= ' s="' . $styleId . '"';

if (CellHelper::isNonEmptyString($cellValue)) {
if ($this->shouldUseInlineStrings) {
$cellXML .= ' t="inlineStr"><is><t>' . $this->stringsEscaper->escape($cellValue) . '</t></is></c>';
$matches = array();
if (preg_match('/=HYPERLINK\("(.*)","(.*)"\)/', $cellValue, $matches)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regex should be changed to support other ways of writing the formula: /=HYPERLINK\([\'"](.*)[\'"],\s*[\'"](.*)[\'"]\)/. This support single and double quotes as well as any number of spaces after the comma (it may also need the same \s before the comma)

// 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 {
$sharedStringId = $this->sharedStringsHelper->writeString($cellValue);
$cellXML .= ' t="s"><v>' . $sharedStringId . '</v></c>';
if ($this->shouldUseInlineStrings) {
$cellXML .= ' t="inlineStr"><is><t>' . $this->stringsEscaper->escape($cellValue) . '</t></is></c>';
} else {
$sharedStringId = $this->sharedStringsHelper->writeString($cellValue);
$cellXML .= ' t="s"><v>' . $sharedStringId . '</v></c>';
}
}
} else if (CellHelper::isBoolean($cellValue)) {
$cellXML .= ' t="b"><v>' . intval($cellValue) . '</v></c>';
Expand Down