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]: WithCharts with 2 series lead to corrupted excel file #4154

Closed
1 task done
johnfau opened this issue Jun 21, 2024 · 1 comment
Closed
1 task done

[Bug]: WithCharts with 2 series lead to corrupted excel file #4154

johnfau opened this issue Jun 21, 2024 · 1 comment

Comments

@johnfau
Copy link

johnfau commented Jun 21, 2024

Is the bug applicable and reproducable to the latest version of the package and hasn't it been reported before?

  • Yes, it's still reproducable

What version of Laravel Excel are you using?

3.1.55

What version of Laravel are you using?

11.11.1

What version of PHP are you using?

8.2.12

Describe your issue

Using the example code at https://docs.laravel-excel.com/3.1/exports/charts.html , I just add one more serie to the chart, the produced excel file cannot be opened ("We found a problem... Trying to recover"). Recovery result in deleting /xl/drawings/drawing1.xml which contain the graph).

How can the issue be reproduced?

Run the following export :

<?php
namespace App\Exports;
use Generator;
use Maatwebsite\Excel\Concerns\FromGenerator;
use Maatwebsite\Excel\Concerns\WithCharts;
use PhpOffice\PhpSpreadsheet\Chart\Chart;
use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues;
use PhpOffice\PhpSpreadsheet\Chart\Legend;
use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
use PhpOffice\PhpSpreadsheet\Chart\Title;

class TestSeries implements WithCharts, FromGenerator
{
    public function generator(): Generator
    {
        yield ["label", "serie1", "serie2"];
        for ($i = 1; $i <= 5; $i  ) {
            yield ["test".$i, $i, $i 1];
        }
    }

    public function charts()
    {
        $label       = [new DataSeriesValues('String', 'Worksheet!$B$1', null, 1)];
        $label2      = [new DataSeriesValues('String', 'Worksheet!$C$1', null, 1)];
        $categories  = [new DataSeriesValues('String', 'Worksheet!$A$2:$A$5', null, 4)];
        $values      = [new DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', null, 4)];
        $values2     = [new DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4)];
        $series = new DataSeries(DataSeries::TYPE_LINECHART, DataSeries::GROUPING_STANDARD,
            range(0, \count($values) - 1), $label, $categories, $values);
        $series2 = new DataSeries(DataSeries::TYPE_LINECHART, DataSeries::GROUPING_STANDARD,
            range(0, \count($values2) - 1), $label2, $categories, $values2);
        /* works well with 1 one of the serie
        $plot   = new PlotArea(null, [$series]);
        $plot   = new PlotArea(null, [$series2]);
        */
        // but doesnt work with both
        $plot   = new PlotArea(null, [$series, $series2]);
        $legend = new Legend();
        $chart  = new Chart('chart name', new Title('chart title'), $legend, $plot);
        $chart->setTopLeftPosition('A12');
        $chart->setBottomRightPosition('N27');
        return $chart;
    }
}

What should be the expected behaviour?

Generate the excel file with a graph containing the 2 series

@johnfau johnfau added the bug label Jun 21, 2024
@stale stale bot added the stale label Aug 22, 2024
Copy link

stale bot commented Aug 28, 2024

This bug report has been automatically closed because it has not had recent activity. If this is still an active bug, please comment to reopen. Thank you for your contributions.

@stale stale bot closed this as completed Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant