Closed
Description
This is:
- [x] a bug report
What is the expected behavior?
When the title of a chart is a cell reference, the title must be set.
What is the current behavior?
An error occurs because the title is not a rich text but a reference to a cell.
What are the steps to reproduce?
We can't reproduce this behavior on a chart from scratch, PhpSpreadsheet allow us to only put a string caption on a title.
Here the XML extract from an Excel chart :
<c:chart>
<c:title>
<c:tx>
<c:strRef>
<c:f>'Worksheet'!$B$41</c:f>
<c:strCache>
<c:ptCount val="1"/>
<c:pt idx="0">
<c:v>My super title in a cell !</c:v>
</c:pt>
</c:strCache>
</c:strRef>
</c:tx>
<c:overlay val="0"/>
<c:spPr>
<a:noFill/>
<a:ln>
<a:noFill/>
</a:ln>
<a:effectLst/>
</c:spPr>
...
</c:title>
</c:chart>
Here my draft for the fix (the value is not dynamic, the range is put directly as string in the title ...) :
private static function chartTitle(SimpleXMLElement $titleDetails, array $namespacesChartMeta)
{
$caption = [];
$titleLayout = null;
foreach ($titleDetails as $titleDetailKey => $chartDetail) {
switch ($titleDetailKey) {
case 'tx':
foreach ($chartDetail as $titleCaptionKey => $titleCaption) {
switch ($titleCaptionKey) {
case 'rich':
foreach ($titleCaption->children($namespacesChartMeta['a']) as $titleKey => $titleDetail) {
switch ($titleKey) {
case 'p':
$titleDetailPart = $titleDetail->children($namespacesChartMeta['a']);
$caption[] = self::parseRichText($titleDetailPart);
}
}
break;
case 'strRef':
foreach ($titleCaption->children($namespacesChartMeta['c']) as $titleKey => $titleDetail) {
switch ($titleKey) {
case 'f':
$caption[] = (string) $titleDetail;
}
}
}
}
break;
case 'layout':
$titleLayout = self::chartLayoutDetails($chartDetail, $namespacesChartMeta);
break;
}
}
return new Title($caption, $titleLayout);
}
I don't know if there is quick fix to transform the caption in dynamic value.
Which versions of PhpSpreadsheet and PHP are affected?
PhpSpreadsheet 1.5.0
PHP 7.1