Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MarekPolok opened this issue May 22, 2024 · 1 comment

Comments

@MarekPolok
Copy link

MarekPolok commented May 22, 2024

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

@oleibman
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants