PhpSpreadsheet
PhpSpreadsheet copied to clipboard
In export HTML to excel don't applying CSS styles
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?
I have a html view in Laravel. In view i use classes for style. All styles included in view.. I want to export it just as it is to Excel
What is the current behavior?
HTML exporting but css not apply
What are the steps to reproduce?
- Install PhpSpreadsheet 1.13
- Use view.blade to generate html
- Save html in temprorary file
- Load this file with
\PhpOffice\PhpSpreadsheet\Reader\Html()->load() - Save with IOFactory::createWriter() writer.
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';
use PhpOffice\PhpSpreadsheet\IOFactory;
// add code that show the issue here...
$data['groups'] = InfoModel::getGroups($faculty_id, $course);
$html = view('exports.export_schedule', $data);
$handle = fopen("schedule.html", "w+");
fwrite($handle, $html);
fclose($handle);
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Html();
$spreadsheat =$reader->load("schedule.html");
$html_writer = IOFactory::createWriter($spreadsheat, "Xlsx");
$html_writer->save("schedule.xlsx");
return response()->download("schedule.xlsx");
### Which versions of PhpSpreadsheet and PHP are affected?
PhpSpreadsheet v1.13
PHP v7.2.5


This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue for you, please try to help by debugging it further and sharing your results. Thank you for your contributions.
Anything new about the issue?
Did anyone solve this issue..
Probably not. It looks like the issue here is that Html Reader processes inline styles, but omits most styles from Css classes. So, if your original Html file was generated by PhpSpreadsheet using $writer->setUseInlineCss(true);, the styles will be preserved, but not otherwise. It looks like it might be difficult to get Html Reader to process the classes.
Reopening, but don't look for a solution any time soon.