ycphs / openxlsx

openxlsx - a fast way to read and write complex xslx files
https://ycphs.github.io/openxlsx/
Other
226 stars 75 forks source link

Excel fail to open the output created from openxlsx with slicer #313

Closed radiance88 closed 1 year ago

radiance88 commented 2 years ago

Describe the bug I created a simple excel file "Slicer_test.xlsx", with some random data, a pivot table and a slicer. Nothing wrong when using R openxlsx. I simply use loadWorkbook to load it and then saveWorkbook to save it as another file. Then when I open the new file it says 'We found a problem with some content in the file. Do you want us to try to recover". If I click "Yes", it says "The workbook cannot be opened or repaired because it is corrupt" To Reproduce

wb <- loadWorkbook("Slicer_test.xlsx") saveWorkbook(wb,"Slicer_test_saved.xlsx")

Expected behavior I expect Excel should be able to open the output file with no problem.

Screenshots image image

Example files If applicable, add example files to help explain y Slicer_test.xlsx our problem (openxlsx and/or Excel created files)

JanMarvin commented 2 years ago

Thanks, confirmed. In the created file xl/workbook.xml contains multiple entries of extLst. That is not supposed to happen and Excel most likely does not like that. I guess I imported that because we were losing some extLst entries, now we have them duplicated. Oh boy

JanMarvin commented 2 years ago

A fix for now:

# import your Slicer_test.xlsx
wb <- openxlsx::loadWorkbook("~/gh_issue_313.xlsx")
# keep only the last extLst (the openxlsx created one in this case)
wb$workbook$extLst <- wb$workbook$extLst[2]
# works in ms365
openxlsx::saveWorkbook(wb, "test.xlsx", overwrite = TRUE)
JanMarvin commented 2 years ago

For some reason openxlsx decided, that it wants some extLst (most likely due to the slicer found on a sheet), though we failed to check if there are extLst elements we could merge with or even overwrite. Appending seems like the worst idea in this case as it leads to broken files for Excel. If bitten by this: they work fine with LibreOffice.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 365 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] commented 1 year ago

This issue was closed because it has been stalled for 7 days with no activity.