Skip to content

Textboxes, shape are not visible when using mergefields in file that contains image (Excel) #4037

@MarekPolok

Description

@MarekPolok

This is:

- [x] a bug report

What is the expected behavior?

Textboxes, Shapes etc should be visible after using merging of fields

What is the current behavior?

Textboxes, Shapes are gone when there is a image in excel.
When Image is removed everything works as expected - shapes, textboxes are not removed
As you can see [[documents_Description]] is changed to merge excel.xslx

Screenshots showing what is the problem:
Orginal file before merging fields:
Screenshot 2024-05-22 at 10 08 19
File after merging fields:
Screenshot 2024-05-22 at 10 09 33

Sample file which is failing:
merge excel.xlsx

What are the steps to reproduce?

We are taking a file and using regex to match merge field inserted in excel and fill it with data from our system.
So we are taking file, process fields and save the document

<?php

public static function Load(File $file): static {
	$fileFullPath = $file->GetFullPath();

	$reader = IOFactory::createReaderForFile($fileFullPath);
	$document = $reader->load($fileFullPath);

	$res = new static;
	$res->spreadsheet = $document;

	return $res;
}

public function MergeToFile(File $sourceFile, IFile $file): void {
	$excelDoc = ExcelDocument::Load($sourceFile);
	$excelDoc->CellSearchReplace(new Regex('/\[\[([\w\/_]+)]]/'), function(string $value, array $matches) {
		$key = $matches[1];
		return $this->fieldValues[$key] ?? $this->getFieldValueFromFunction($key) ?? '';
	});
	$excelDoc->SaveToFile($file);
}

Which versions of PhpSpreadsheet and PHP are affected?

PhpSpreadsheet version: 2.1.0
PHP version: 8.3.2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions