PhpSpreadsheet
PhpSpreadsheet copied to clipboard
Error opening template xlsx with charts using cell reference chartTitles
This is:
- [x ] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)
What is the expected behavior?
Existing template chart titles refers to a cell values on a specific sheet. When importing the template I am expecting the chart titles to be recognized. Seems to be same issue as here: https://github.com/PHPOffice/PhpSpreadsheet/issues/749
What is the current behavior?
Upon opening the template file, getting warning/errors for every chart that has a title based on a cell reference:
PhpOffice\PhpSpreadsheet\Reader\Xlsx\Chart::chartTitle(): Node no longer exists in /home/myDir/php/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx/Chart.php on line 360
What are the steps to reproduce?
Create a template with two sheets, Sheet1 is raw data, Sheet2 are preformatted charts with each chartTitle referring to a specific cell on Sheet1.
Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:
<?php
require __DIR__ . '/vendor/autoload.php';
// Open existing template file
$mainTempName = "$baseDir/reports/MainReportTemplate.xlsx" ;
$mainTempReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader("Xlsx") ;
$mainTempFile = $mainTempReader->load($mainTempName, \PhpOffice\PhpSpreadsheet\Reader\IReader::LOAD_WITH_CHARTS) ;
// just opening the template file causes the warning/error, and then all saved files are missing chartTitles.
What features do you think are causing the issue
- [ ] Reader
- [ ] Writer
- [ ] Styles
- [ ] Data Validations
- [ ] Formula Calculations
- [x ] Charts
- [ ] AutoFilter
- [ ] Form Elements
Does an issue affect all spreadsheet file formats? If not, which formats are affected?
Don't know, only testing with opening xlsx files
Which versions of PhpSpreadsheet and PHP are affected?
phpspreadsheet: 1.24.1 php: 7.3
I can confirm your reported behavior. It's easy to eliminate the error. I'm not sure how easy it is to get the behavior you want. At the moment, Title is expected to be a static property. I'm not sure of all that would be needed to make it dynamic. It seems a lot more complicated than you might think.
@oleibman To eliminate the error, I suppose the work around is removing the title from the chart? I can do it temporarily and simply add a centered cell above the chart that references the title cell on the data page....same effect but not as clean. Not certain how to categorize it. A template with a chart title referencing a cell causes an error (thus a bug), but at the same time its clear the Charts.php base code does not support this (thus a feature request). And no, I don't imagine its easy to add.