Skip to content

Error in MS Excel after filling XLSX form with PhpOffice\PhpSpreadsheet #4145

@sarunas-ven

Description

@sarunas-ven

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?

Using prefilled template fill some data and write into new file. New file created from template that opens using MS Excel without errors.

What is the current behavior?

Using prefilled template fill some data and write into new file. New file created from template opens using MS Excel with error: "We found a problem with some content in 'my_file.xlsx'. Do you want us to try to recover as much as we can? If you trust the source of this workbook, click Yes."

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

// Reading the file:
$reader = new PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$reader->setReadDataOnly(false);
$spreadsheet = $reader->load('SEPA.xlsx');
$currentTab = $spreadsheet->getSheetByName('CarrierSchedule');

// Saving file:
$writer = new PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
$writer->save('my_file.xlsx');

// Closing file:
$spreadsheet->disconnectWorksheets();
unset($spreadsheet);
unset($currentTab);

The filling cells data is skipped in the example because just opening template and saving into new file is enough to get the error.

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.

This is the template file that is used to fill and save to new file. It is not created by me, it is the official template from government institution.
SEPA.xlsx

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?

It possibly affects only xlsx files.

Which versions of PhpSpreadsheet and PHP are affected?

PHP 8.2
phpoffice/phpspreadsheet: 1.29.0

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