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

Export HTML to XLSX cause broken file #4231

Open
1 of 8 tasks
darkvovich opened this issue Nov 13, 2024 · 1 comment
Open
1 of 8 tasks

Export HTML to XLSX cause broken file #4231

darkvovich opened this issue Nov 13, 2024 · 1 comment

Comments

@darkvovich
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?

Export HTML to XLSX cause broken file in latestPhpSpreadsheet v3.4.0

What is the current behavior?

When I use this code

What are the steps to reproduce?

I catch html via ob_start() + ob_get_clean() and when i push it to writer - it return broken file! But when I POST this html to external script (similar) - it save correct file.

<?php
require __DIR__ . '/vendor/autoload.php';

$html = ob_get_clean();
$html = preg_replace("/\s+|\n+|\r/", ' ', $html);

$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();

$tableName = 'Act for '.$aCompanyName;

$reader = new \PhpOffice\PhpSpreadsheet\Reader\Html();
$spreadsheet = $reader->loadFromString(trim($html));

// redirect output to client browser
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="'.$tableName.'.xlsx"');
header('Cache-Control: max-age=0');

$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
$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?

Which versions of PhpSpreadsheet and PHP are affected?

3.4.0

@oleibman
Copy link
Collaborator

I would have to see what's in $html after ob_get_clean to have any idea what's going wrong. Can you upload it?

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