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

Chart Position Inconsistent with Original Spreadsheet #3912

Open
3 of 8 tasks
roland-jungwirth opened this issue Feb 20, 2024 · 2 comments
Open
3 of 8 tasks

Chart Position Inconsistent with Original Spreadsheet #3912

roland-jungwirth opened this issue Feb 20, 2024 · 2 comments

Comments

@roland-jungwirth
Copy link

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?

If I read a spreadsheet with a chart, I expect the chart to be in the same position when I output the spreadsheet.

What is the current behavior?

The chart is in B24, but - after I have read and output it - it is in D13.

Additional background

I was trying to insert some rows and noticed that the chart was not being moved down, although this is the standard behaviour for Excel (reproduce: open the attached test.xlsx, mark lines 20-22, right click, click "Insert"). During my testing this issue came up.

What are the steps to reproduce?

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';

$reader = IOFactory::createReader( 'Xlsx' );
$reader->setIncludeCharts( TRUE );

$spreadsheet = $reader->load( '/test.xlsx' );

// Set the headers to force a download of the Excel file
header( 'Content-Type: application/vnd.ms-excel' );
header( 'Content-Disposition: attachment; filename="test-output.xlsx"' );
header( 'Cache-Control: max-age=0' );

//$input_worksheet = $spreadsheet->getSheetByName( 'Sheet1' );
//$input_worksheet->insertNewRowBefore( 21, 10 );

// Create a writer and send the Excel file to the browser
$writer = new Xlsx( $spreadsheet );

ob_end_clean();
$writer->setIncludeCharts( TRUE );
$writer->save( 'php://output' );

If this is an issue with reading a specific spreadsheet file, then it may be appropriate to provide a sample file that demonstrates the problem; but please keep it as small as possible, and sanitize any confidential information before uploading.

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?

Only tested with xlsx.

Which versions of PhpSpreadsheet and PHP are affected?

PHP 8.1, PhpSpreadsheet: whatever this version is: #3767

test.xlsx

@oleibman
Copy link
Collaborator

Unable to duplicate. When I load and save the spreadsheet to a new file, the chart is in B24, as expected. I am, admittedly, running from the command line rather than a web server, but I do not see why that should matter.

You do not seem to be specifying includeCharts on the writer, but that would cause the chart to be omitted from the output file, not moved to a different location.

@roland-jungwirth
Copy link
Author

I omitted includeCharts by accident - it definitely shows in the output. It might be due to a different version of phpspreadsheet?

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