-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Open
Labels
Description
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:

File after merging fields:

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