mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-10-05 11:28:33 +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
@@ -299,6 +299,36 @@ class HtmlTest extends TestCase
|
||||
unlink($filename);
|
||||
}
|
||||
|
||||
public function testCanLoadFromString()
|
||||
{
|
||||
$html = '<table>
|
||||
<tr>
|
||||
<td>Hello World</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Hello<br />World</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Hello<br>World</td>
|
||||
</tr>
|
||||
</table>';
|
||||
$spreadsheet = (new Html())->loadFromString($html);
|
||||
$firstSheet = $spreadsheet->getSheet(0);
|
||||
|
||||
$cellStyle = $firstSheet->getStyle('A1');
|
||||
self::assertFalse($cellStyle->getAlignment()->getWrapText());
|
||||
|
||||
$cellStyle = $firstSheet->getStyle('A2');
|
||||
self::assertTrue($cellStyle->getAlignment()->getWrapText());
|
||||
$cellValue = $firstSheet->getCell('A2')->getValue();
|
||||
$this->assertContains("\n", $cellValue);
|
||||
|
||||
$cellStyle = $firstSheet->getStyle('A3');
|
||||
self::assertTrue($cellStyle->getAlignment()->getWrapText());
|
||||
$cellValue = $firstSheet->getCell('A3')->getValue();
|
||||
$this->assertContains("\n", $cellValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $html
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user