Allow HTML Reader to load from string

We often want to export a table as an excel sheet. The system renders the
html and it seems like a waste of time to write it to the file system to
use the reader. This allows us to render the html and then just pass it to
a reader

Closes #1136
This commit is contained in:
Nathanael Noblet
2019-08-14 10:04:21 -06:00
committed by Adrien Crivelli
parent 34675bdf5d
commit 95c8bb9918
4 changed files with 106 additions and 11 deletions
@@ -875,3 +875,31 @@ $writer->save('write.xls');
```
Notice that it is ok to load an xlsx file and generate an xls file.
## Generating Excel files from HTML content
If you are generating an Excel file from pre-rendered HTML content you can do so
automatically using the HTML Reader. This is most useful when you are generating
Excel files from web application content that would be downloaded/sent to a user.
For example:
```php
$htmlString = '<table>
<tr>
<td>Hello World</td>
</tr>
<tr>
<td>Hello<br />World</td>
</tr>
<tr>
<td>Hello<br>World</td>
</tr>
</table>';
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Html();
$spreadsheet = $reader->loadFromString($htmlString);
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls');
$writer->save('write.xls');
```