Xlsx Writer Support for WMF Files (#2339)
PR #1844 fixes it, but changes were requested. It has been almost 3 months and those changes have not been made. This PR replaces that one; it should be suitable for all supported releases of PHP through 8.1, and includes a formal unit test. Fixes #1685 Closes #1844
This commit is contained in:
parent
858e073063
commit
26c26ae8df
|
|
@ -5660,16 +5660,6 @@ parameters:
|
|||
count: 2
|
||||
path: src/PhpSpreadsheet/Writer/Xlsx/Comments.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$arr1 of function array_diff expects array, array\\|null given\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Writer/Xlsx/ContentTypes.php
|
||||
|
||||
-
|
||||
message: "#^Cannot access offset 2 on array\\|false\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Writer/Xlsx/ContentTypes.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#2 \\$content of method XMLWriter\\:\\:writeElement\\(\\) expects string\\|null, int given\\.$#"
|
||||
count: 1
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ class ContentTypes extends WriterPart
|
|||
if ($spreadsheet->hasRibbonBinObjects()) {
|
||||
// Some additional objects in the ribbon ?
|
||||
// we need to write "Extension" but not already write for media content
|
||||
$tabRibbonTypes = array_diff($spreadsheet->getRibbonBinObjects('types'), array_keys($aMediaContentTypes));
|
||||
$tabRibbonTypes = array_diff($spreadsheet->getRibbonBinObjects('types') ?? [], array_keys($aMediaContentTypes));
|
||||
foreach ($tabRibbonTypes as $aRibbonType) {
|
||||
$mimeType = 'image/.' . $aRibbonType; //we wrote $mimeType like customUI Editor
|
||||
$this->writeDefaultContentType($objWriter, $aRibbonType, $mimeType);
|
||||
|
|
@ -192,7 +192,7 @@ class ContentTypes extends WriterPart
|
|||
if (File::fileExists($pFile)) {
|
||||
$image = getimagesize($pFile);
|
||||
|
||||
return image_type_to_mime_type($image[2]);
|
||||
return image_type_to_mime_type((is_array($image) && count($image) >= 3) ? $image[2] : 0);
|
||||
}
|
||||
|
||||
throw new WriterException("File $pFile does not exist");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Writer\Xlsx;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
|
||||
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
|
||||
|
||||
class WmfTest extends AbstractFunctional
|
||||
{
|
||||
/**
|
||||
* Test save and load XLSX file with wmf image.
|
||||
*/
|
||||
public function testWmf(): void
|
||||
{
|
||||
// Read spreadsheet from file
|
||||
$inputFilename = 'tests/data/Writer/XLSX/wmffile.xlsx';
|
||||
$reader = new Xlsx();
|
||||
$spreadsheet = $reader->load($inputFilename);
|
||||
$drawings = $spreadsheet->getActiveSheet()->getDrawingCollection();
|
||||
self::assertCount(1, $drawings);
|
||||
$drawing = $drawings[0];
|
||||
self::assertSame('wmf', $drawing->getExtension());
|
||||
|
||||
// Save spreadsheet to file and read it back
|
||||
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx');
|
||||
$drawings = $reloadedSpreadsheet->getActiveSheet()->getDrawingCollection();
|
||||
self::assertCount(1, $drawings);
|
||||
$drawing = $drawings[0];
|
||||
self::assertSame('wmf', $drawing->getExtension());
|
||||
|
||||
$spreadsheet->disconnectWorksheets();
|
||||
$reloadedSpreadsheet->disconnectWorksheets();
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Loading…
Reference in New Issue