I am using the PhpOfficePhpSpreadsheet package to fill the fields of a SEPA.xlsx form. The fields are filled successfully, but when the filled form is saved to a new file, opening that file in MS Excel results in an error indicating that something is wrong with the file and it attempts to repair it.
Here is short example code:
// Reading the file:
$reader = new PhpOfficePhpSpreadsheetReaderXlsx();
$reader->setReadDataOnly(false);
$this->spreadsheet = $reader->load($this->inputXlsFile);
$this->currentTab = $this->spreadsheet->getSheetByName(self::ORIGINAL_FORM_TAB_NAME);
// Filling cells:
$this->currentTab->getCell(self::B1_PRODUCT_NAME_CELL)->setValue('Product name');
// Saving file:
$writer = new PhpOfficePhpSpreadsheetWriterXlsx($this->spreadsheet);
$writer->setPreCalculateFormulas(false);
$writer->save($this->outputXlsFilePath);
// Closing file:
$this->spreadsheet->disconnectWorksheets();
unset($this->spreadsheet);
I have tried:
- different settings using reader
PhpOfficePhpSpreadsheetReader
and writerPhpOfficePhpSpreadsheetWriter
- using empty strings for cells when data is missing
- not setting any values for cells when data is missing
- cloning data into new worksheet and then filling.
The problem/bug: after filling xlsx form and saving it to new file using MS Excel on Mac shows error: “We found a problem with some content in ‘my_file.xlsx’. Do you want us to try to recover as much as we can? If you trust the source of this workbook, click Yes.”.
Expected behavior: the new file opens using MS Excel without errors.