Skip to content

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

Open
@homersimpsons

Description

@homersimpsons

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions