PHPOffice / PhpSpreadsheet

A pure PHP library for reading and writing spreadsheet files
https://phpspreadsheet.readthedocs.io
MIT License
13.28k stars 3.43k forks source link

In export HTML to excel don't applying CSS styles #1515

Open rahmatullo-1892 opened 4 years ago

rahmatullo-1892 commented 4 years ago

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)
stale[bot] commented 4 years ago

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.

NicoxDJ commented 3 years ago

Anything new about the issue?

izengmac commented 2 months ago

Did anyone solve this issue..

oleibman commented 2 months ago

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 commented 2 months ago

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