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

Uncaught TypeError: PhpOffice\PhpSpreadsheet\Writer\Xlsx\Chart::writePlotGroup(): Argument #6 ($plotGroupingType) must be of type string, null given #3975

Open
3 of 9 tasks
homersimpsons opened this issue Apr 6, 2024 · 0 comments · May be fixed by #3976

Comments

@homersimpsons
Copy link

homersimpsons commented Apr 6, 2024

This is:

  • a bug report

What is the expected behavior?

PhpSpreadsheet sould not fail loading and writing this file

What is the current behavior?

PhpSpreasheet throws a TypeError when writing the file

What are the steps to reproduce?

(for now I do not have a reproduction without an excel file)

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

use PhpOffice\PhpSpreadsheet\Reader\IReader;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader;
use PhpOffice\PhpSpreadsheet\Writer\IWriter;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter;

require_once "vendor/autoload.php";

$reader = new XlsxReader();
$spreadsheet = $reader->load("example_plot_grouping_type_null.xlsx", IReader::LOAD_WITH_CHARTS);

$writer = new XlsxWriter($spreadsheet);
$writer->save("example_updated.xlsx", IWriter::SAVE_WITH_CHARTS);

Here is the file: example_plot_grouping_type_null.xlsx

Note that I was able to generate such a file from scratch on Google Sheet: sheet_with_combo_chart.xlsx

  1. Create a new sheet
  2. Create 2 columns of data
  3. Create a chart on those columns
  4. In the settings of the chart chose combo chart
  5. Remove X axis
  6. Add missing Y axis

What features do you think are causing the issue

  • Reader
  • Writer
  • Styles
  • Data Validations
  • Formula Calculations
  • Charts
  • AutoFilter
  • Form Elements

Does an issue affect all spreadsheet file formats? If not, which formats are affected?

I'm not sure

Which versions of PhpSpreadsheet and PHP are affected?

Latest version of PhpSpreadsheet (2.0.0) with PHP 8.1.2-1ubuntu2.14 (but should be any supported php version.

Analysis

This most likely is caused because the following call can return null:

$plotGroupingType = $plotGroup->getPlotGrouping();

And because the parameter is passed by reference:

private function writePlotGroup(?DataSeries $plotGroup, string $groupType, XMLWriter $objWriter, bool &$catIsMultiLevelSeries, bool &$valIsMultiLevelSeries, string &$plotGroupingType): void

Thank you for this awesome library!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant