mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-09 01:26:51 +00:00
2c8177a319
The tests stay; they just no longer run in separate processes. I think that only 2 tests still require separate processes - Helper/SampleTest and Tcpdf/NoDieTest. Aside from a new internal method in IOFactory, all the changes here are to test members.
46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Reader\Html;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Reader\Html;
|
|
use PhpOffice\PhpSpreadsheet\Shared\File;
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
|
class HtmlHelper
|
|
{
|
|
public static function createHtml(string $html): string
|
|
{
|
|
$filename = File::temporaryFilename();
|
|
file_put_contents($filename, $html);
|
|
|
|
return $filename;
|
|
}
|
|
|
|
public static function loadHtmlIntoSpreadsheet(string $filename, bool $unlink = false, ?bool $allowExternalImages = null): Spreadsheet
|
|
{
|
|
$html = new Html();
|
|
if ($allowExternalImages !== null) {
|
|
$html->setAllowExternalImages($allowExternalImages);
|
|
}
|
|
$spreadsheet = $html->load($filename);
|
|
if ($unlink) {
|
|
unlink($filename);
|
|
}
|
|
|
|
return $spreadsheet;
|
|
}
|
|
|
|
public static function loadHtmlStringIntoSpreadsheet(string $content, ?bool $allowExternalImages = null): Spreadsheet
|
|
{
|
|
$html = new Html();
|
|
if ($allowExternalImages !== null) {
|
|
$html->setAllowExternalImages($allowExternalImages);
|
|
}
|
|
$spreadsheet = $html->loadFromString($content);
|
|
|
|
return $spreadsheet;
|
|
}
|
|
}
|