mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-12 11:06:28 +00:00
dfab88262a
Fix #4823. When writing a spreadsheet to Html, a data Uri can be used if `embedImages` is true. Reading such an Html spreadsheet and attempting to write it to Xlsx results in an Exception. It should be noted that Excel itself cannot open the Html properly; none of the images are present. The PhpSpreadsheet problem arises not with the inclusion of the image, but rather with attempting to include the appropriate entry in `[ContentTypes].xml`. This PR corrects that problem. For the record, Xls Writer does not have a problem with this situation. Just to demonstrate that, a parallel test for Xls Writer is added in addition to the new Xlsx Writer test.
39 lines
1.4 KiB
PHP
39 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Writer\Xls;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Reader\Html as HtmlReader;
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing;
|
|
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
|
|
|
|
class Issue4823Test extends AbstractFunctional
|
|
{
|
|
/**
|
|
* Xlsx Writer did not handle image data uri's correctly (Xls was okay).
|
|
*/
|
|
public function testIssue4823(): void
|
|
{
|
|
$infile = 'tests/data/Reader/HTML/issue.4823.html';
|
|
$reader = new HtmlReader();
|
|
$spreadsheet = $reader->load($infile);
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
$drawings = $sheet->getDrawingCollection();
|
|
self::assertCount(1, $drawings);
|
|
$drawing = $drawings[0];
|
|
self::assertInstanceOf(Drawing::class, $drawing);
|
|
self::assertStringStartsWith('data:image/png;base64,', $drawing->getPath());
|
|
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xls');
|
|
$spreadsheet->disconnectWorksheets();
|
|
$rsheet = $reloadedSpreadsheet->getActiveSheet();
|
|
$drawings = $rsheet->getDrawingCollection();
|
|
self::assertCount(1, $drawings);
|
|
$drawing = $drawings[0];
|
|
self::assertInstanceOf(MemoryDrawing::class, $drawing);
|
|
self::assertSame('image/png', $drawing->getMimeType());
|
|
$reloadedSpreadsheet->disconnectWorksheets();
|
|
}
|
|
}
|