mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-20 15:16:36 +00:00
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:
committed by
Adrien Crivelli
parent
34675bdf5d
commit
95c8bb9918
@@ -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');
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user