PhpSpreadsheet icon indicating copy to clipboard operation
PhpSpreadsheet copied to clipboard

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

Open MarekPolok opened this issue 1 year ago • 3 comments

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

MarekPolok avatar May 22 '24 08:05 MarekPolok

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.

oleibman avatar May 22 '24 16:05 oleibman

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

I also encounter the same problem, is there a solution?

xiongmao-p avatar Nov 26 '24 07:11 xiongmao-p

No progress to report.

oleibman avatar Nov 26 '24 08:11 oleibman