Skip to content

Writer\Xlsx() produce broken files #4200

@madorin

Description

@madorin

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)

I have an xlsx excel file template, open it, fill some cells and using Writer\Xlsx to save the output

Used template: template.xlsx
Generated broken output: output.xlsx

What is the expected behavior?

To generate an excel compatible file.

What is the current behavior?

It produces a broken file. However, LibreOffice opens it fine.
Xls writer, (without "x" at the end) works fine.

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


# Read
$reader = new Spreadsheet\Reader\Xlsx();
$workbook = $reader->load('path/to/template.xlsx');
unset($reader);

# Write
$writer = new Spreadsheet\Writer\Xlsx($workbook);
ob_start();
$writer->save('php://output');
$content = ob_get_clean();
unset($writer);
header('Content-Disposition: attachment; filename="report.xlsx"');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Length: ' . strlen($content));
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate');
echo $content;
unset($content);

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?

XLSX Writer is affected, XLS writer works fine.

Which versions of PhpSpreadsheet and PHP are affected?

v3.3, v2.3

In earlier v1.x versions it worked fine. Not sure when it was broken.

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