PhpSpreadsheet
PhpSpreadsheet copied to clipboard
Writing XLSX from templates don't keep all archive files
I am loading a template file, editing it and then saving it, like this :
$filename = 'templateImportFactureVente_CAF.xlsx';
$spreadsheet = IOFactory::load( __DIR__ . '/../../' . $filename );
// edit file
$writer = IOFactory::createWriter( $spreadsheet, 'Xlsx' );
$writer->save( $filename );
The template file contains some required .xml files in the XLSX archive. When saving it, some of the .xml files are missing, which is problematic for the feature I'm building.
xmlMaps.xml is missing when saving
customXml is missing when saving
You can see by the size of the folders that some files are missing from these too.
Is there a way to do what I want? I just want to add lines to the templates, while keeping all .xml file structure that are necessary. I tried to look into the save() method but it's hard to understand everything that's happening.
templateImportFactureVente_CAF.xlsx
Using 3.3.0
I think this would be difficult to support. Which doesn't mean it can't be done, but it will take a lot of research and time. In the meantime, Excel 365 thinks your file is corrupt:
Excel completed file level validation and repair. Some parts of this workbook may have been repaired or discarded.
Removed Feature: AutoFilter from /xl/tables/table1.xml part (Table)
Removed Feature: Table from /xl/tables/table1.xml part (Table)
Removed Feature: Table from /xl/tables/tableSingleCells1.xml part (Table)
Removed Feature: AutoFilter from /xl/tables/table2.xml part (Table)
Removed Feature: Table from /xl/tables/table2.xml part (Table)
Removed Feature: Table from /xl/tables/tableSingleCells2.xml part (Table)
Removed Records: Table from /xl/xmlMaps.xml part (XML Table)
Do you not see these messages when you open the file? If not, what release of Excel are you using? If so, is it possible to supply a non-corrupt version of the file so that I can research?
@oleibman Sorry, don't know what I uploaded haha. I edited my post and uploaded the correct version.
I thought about extending the Writer/Xlsx.php class, as I saw some logic iterating on the ZipArchive, but that seems to be a lot of work indeed.
Thank you, the new file looks okay. Just because I don't know anything about it, when I open it, is there anything that differs from how it would appear if there was no custom xml?