mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-17 21:46:37 +00:00
feat: add drawing pass-through support for unsupported elements
This commit is contained in:
@@ -60,6 +60,14 @@ abstract class BaseReader implements IReader
|
||||
*/
|
||||
protected bool $createBlankSheetIfNoneRead = false;
|
||||
|
||||
/**
|
||||
* Enable drawing pass-through?
|
||||
* Identifies whether the Reader should preserve unsupported drawing elements (shapes, grouped images, etc.)
|
||||
* by storing the original XML for pass-through during write operations.
|
||||
* When enabled, drawings cannot be modified programmatically but are preserved exactly.
|
||||
*/
|
||||
protected bool $enableDrawingPassThrough = false;
|
||||
|
||||
/**
|
||||
* IReadFilter instance.
|
||||
*/
|
||||
@@ -125,6 +133,18 @@ abstract class BaseReader implements IReader
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEnableDrawingPassThrough(): bool
|
||||
{
|
||||
return $this->enableDrawingPassThrough;
|
||||
}
|
||||
|
||||
public function setEnableDrawingPassThrough(bool $enableDrawingPassThrough): self
|
||||
{
|
||||
$this->enableDrawingPassThrough = $enableDrawingPassThrough;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** @return null|string[] */
|
||||
public function getLoadSheetsOnly(): ?array
|
||||
{
|
||||
|
||||
@@ -1481,6 +1481,11 @@ class Xlsx extends BaseReader
|
||||
$xmlDrawing = $this->loadZipNoNamespace($fileDrawing, '');
|
||||
$xmlDrawingChildren = $xmlDrawing->children(Namespaces::SPREADSHEET_DRAWING);
|
||||
|
||||
// Store drawing XML for pass-through if enabled
|
||||
if ($this->enableDrawingPassThrough) {
|
||||
$unparsedDrawings[$drawingRelId] = $xmlDrawing->asXML();
|
||||
}
|
||||
|
||||
if ($xmlDrawingChildren->oneCellAnchor) {
|
||||
foreach ($xmlDrawingChildren->oneCellAnchor as $oneCellAnchor) {
|
||||
$oneCellAnchor = self::testSimpleXml($oneCellAnchor);
|
||||
|
||||
@@ -23,6 +23,12 @@ class Drawing extends WriterPart
|
||||
*/
|
||||
public function writeDrawings(\PhpOffice\PhpSpreadsheet\Worksheet\Worksheet $worksheet, bool $includeCharts = false): string
|
||||
{
|
||||
// Check if we have stored drawing XML (pass-through for unsupported elements)
|
||||
$unparsedLoadedData = $worksheet->getParentOrThrow()->getUnparsedLoadedData();
|
||||
if (isset($unparsedLoadedData['sheets'][$worksheet->getCodeName()]['Drawings'])) {
|
||||
return reset($unparsedLoadedData['sheets'][$worksheet->getCodeName()]['Drawings']);
|
||||
}
|
||||
|
||||
// Create XML writer
|
||||
$objWriter = null;
|
||||
if ($this->getParentWriter()->getUseDiskCaching()) {
|
||||
|
||||
Reference in New Issue
Block a user