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

Bug: Setting fill color on line chart corrupts chart in XLSX writer. #589

Closed
madrussa opened this issue Jul 10, 2018 · 1 comment
Closed

Comments

@madrussa
Copy link

When setting the fill color property on a data series within a line chart and exporting it using the XLSX writer the chart becomes corrupt. The XLSX Chart writer has a bug on line:


It should not add the <c:spPr /> tag with colour properties here. It should add them to the <c:spPr /> tag generated for the line which occurs here:
https://github.com/PHPOffice/PhpSpreadsheet/blob/develop/src/PhpSpreadsheet/Writer/Xlsx/Chart.php#L1140

My workaround is to use a custom writer and I applied my fixes as below:
Line 1079:

$plotLabel = $plotGroup->getPlotLabelByIndex($plotSeriesIdx);
if ($plotLabel && $groupType !== DataSeries::TYPE_LINECHART &&
    $groupType !== DataSeries::TYPE_STOCKCHART
) {
    $fillColor = $plotLabel->getFillColor();
    if ($fillColor !== null) {
        $objWriter->startElement('c:spPr');
        $objWriter->startElement('a:solidFill');
        $objWriter->startElement('a:srgbClr');
        $objWriter->writeAttribute('val', $fillColor);
        $objWriter->endElement();
        $objWriter->endElement();
        $objWriter->endElement();
    }
}

Line 1143:

if ($groupType == DataSeries::TYPE_STOCKCHART) {
    $objWriter->startElement('a:noFill');
    $objWriter->endElement();
} elseif ($plotLabel && $plotLabel->getFillColor() !== null) {
    $objWriter->startElement('a:solidFill');
    $objWriter->startElement('a:srgbClr');
    $objWriter->writeAttribute('val', $plotLabel->getFillColor());
    $objWriter->endElement();
    $objWriter->endElement();
}

This probably isn't the best solution though as I don't know what impact it has on other chart types yet. I only know if affects line charts.

@stale
Copy link

stale bot commented Sep 8, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If this is still an issue for you, please try to help by debugging it further and sharing your results.
Thank you for your contributions.

@stale stale bot added the stale label Sep 8, 2018
@stale stale bot closed this as completed Sep 15, 2018
tiagomalheiro added a commit to tiagomalheiro/PhpSpreadsheet that referenced this issue May 31, 2019
tiagomalheiro added a commit to tiagomalheiro/PhpSpreadsheet that referenced this issue May 31, 2019
tiagomalheiro added a commit to tiagomalheiro/PhpSpreadsheet that referenced this issue Mar 17, 2021
tiagomalheiro added a commit to tiagomalheiro/PhpSpreadsheet that referenced this issue Mar 17, 2021
tiagomalheiro added a commit to tiagomalheiro/PhpSpreadsheet that referenced this issue Nov 1, 2021
PowerKiKi pushed a commit to tiagomalheiro/PhpSpreadsheet that referenced this issue Nov 23, 2021
When the fill color property of `DataSeries.plotLabel` using a
DataSeriesValues on a line chart is set, the XLSX file written
is corrupted, and MSExcel2016 removes the drawing1.xml if forced open.

This problem was already documented on issue PHPOffice#589 along with a possible
solution. So all credits go to @madrussa. I am only submitting the PR.

Fixes PHPOffice#589
Closes PHPOffice#1930
PowerKiKi pushed a commit that referenced this issue Nov 23, 2021
When the fill color property of `DataSeries.plotLabel` using a
DataSeriesValues on a line chart is set, the XLSX file written
is corrupted, and MSExcel2016 removes the drawing1.xml if forced open.

This problem was already documented on issue #589 along with a possible
solution. So all credits go to @madrussa. I am only submitting the PR.

Fixes #589
Closes #1930
@oleibman oleibman removed the stale label Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants