PhpSpreadsheet icon indicating copy to clipboard operation
PhpSpreadsheet copied to clipboard

In export HTML to excel don't applying CSS styles

Open rahmatullo-1892 opened this issue 5 years ago • 5 comments

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?

  1. Install PhpSpreadsheet 1.13
  2. Use view.blade to generate html
  3. Save html in temprorary file
  4. Load this file with \PhpOffice\PhpSpreadsheet\Reader\Html()->load()
  5. 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
![Безымянный](https://user-images.githubusercontent.com/47203438/83969453-90e51500-a8e9-11ea-8c49-6acb63ee649c.png)
![Безымянный2](https://user-images.githubusercontent.com/47203438/83969455-92164200-a8e9-11ea-8fbc-f02c3d1f075e.png)

rahmatullo-1892 avatar Jun 07 '20 13:06 rahmatullo-1892

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.

stale[bot] avatar Aug 08 '20 08:08 stale[bot]

Anything new about the issue?

NicoxDJ avatar Dec 03 '20 17:12 NicoxDJ

Did anyone solve this issue..

izengmac avatar Jul 05 '24 11:07 izengmac

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.

oleibman avatar Jul 06 '24 13:07 oleibman

Reopening, but don't look for a solution any time soon.

oleibman avatar Jul 08 '24 03:07 oleibman