PhpSpreadsheet
PhpSpreadsheet copied to clipboard
Textboxes, shape are not visible when using mergefields in file that contains image (Excel)
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
Limited support for form controls was added by PR #3130. The keyword in this case is "limited". We can read them and write them (at least some of the time), but can't actually do anything in the code with them. I agree that we aren't reading your file correctly. I will see if we can do anything about that.
This is:
- [x] a bug reportWhat 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
I also encounter the same problem, is there a solution?
No progress to report.
File after merging fields: 