Search code examples
xmlexcelzip7zip

recreate excel .xlsx file from unzipped xml folder


I'm trying to convert a folder of xml that was created by unzipping an excel file back into an excel .xlsx. But I get the error

The workbook cannot be opened or repaired by Microsoft Excel because it is corrupt

A minimal reproducible example to generate this error:

  1. Create a new blank spreadsheet in Excel
  2. Enter "test" in cell A1
  3. Save as test.xlsx
  4. Rename file to test.zip
  5. Unzip test.zip as a folder named test
  6. Compress test into test_new.zip
  7. Rename test_new.zip as test_new.xlsx
  8. Open test_new.xlsx with Excel

For zipping and unzipping I have used 7zip, WinZip and PeaZip, all with the same result. What am I doing wrong, and how can I turn unzipped excel workbooks back into their original form?


Solution

  • I managed eventually to find the solution to this myself. The key is that when creating the new zip file, it is necessary to only add the contents of the unzipped folder into the archive. Not the whole folder itself!