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

Writing XLSX from templates don't keep all archive files #4394

Open
mdiasCP opened this issue Mar 4, 2025 · 3 comments
Open

Writing XLSX from templates don't keep all archive files #4394

mdiasCP opened this issue Mar 4, 2025 · 3 comments

Comments

@mdiasCP
Copy link

mdiasCP commented Mar 4, 2025

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.

Image

Image
xmlMaps.xml is missing when saving

Image
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

@oleibman
Copy link
Collaborator

oleibman commented Mar 4, 2025

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?

@mdiasCP
Copy link
Author

mdiasCP commented Mar 5, 2025

@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.

@oleibman
Copy link
Collaborator

oleibman commented Mar 6, 2025

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?

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

No branches or pull requests

2 participants