PhpSpreadsheet icon indicating copy to clipboard operation
PhpSpreadsheet copied to clipboard

Support RichText cells in HTML Reader

Open jayredfin opened this issue 3 years ago • 1 comments

This is:

- [ ] a bug report
- [X] 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?

When exporting an html table, cell's with mixed styling should be properly converted to RichText runs.

What is the current behavior?

All the styling in a given cell is applied to the entire cell. For example: a cell with this content "Bold word and italic word" would be exported as "Bold word and italic word" There are a couple of TODOs in "src/PhpSpreadsheet/Reader/Html.php" that seem to indicate this feature is intended to be implemented.

What are the steps to reproduce?

Use the HTML reader to load an HTML string with a table and td values containing mixed bold and italicized text.

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

$htmlString = '<table><tbody>
    <tr>
      <td class="row_0 col_0"><p><strong>Bold</strong></p></td>
      <td class="row_0 col_1"><p><em>Italic</em></p></td>
    </tr>
    <tr>
      <td class="row_1 col_0"><p><a href="https://google.com/" target="_blank" rel="noopener nofollow noreferrer">Google</a></p></td>
      <td class="row_1 col_1"><p><em>Vestibulum</em> <strong>ante ipsum</strong> primis in faucibus orci luctus et ultrices posuere cubilia Curae. <a href="http://google.com" target="_blank" rel="noopener nofollow noreferrer">Google</a>.</p></td>
    </tr>
  </tbody></table>';

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

Which versions of PhpSpreadsheet and PHP are affected?

PhpSpreadsheet 1.21 PHP 7.4

jayredfin avatar Jan 17 '22 17:01 jayredfin

I'm also interested on this !

simogeo avatar Feb 10 '22 13:02 simogeo