Open uvedhe opened 5 years ago
When investigating (using zip -l filename
) the original input file, and the corrupted file output by openxlsx
(generated using my code above), I notice that the former has a folder customXml/
with a number of files, but the latter doesn't.
Could this be the problem? that openxlsx is not importing (and/or exporting) these files?
I found the issue: when writing to an existing sheet, if the target cells that we're writing to contain formulas, the resulting XLSX file will be corrupt.
@awalker89 , is there a way to resolve this? Or issue a warning to the user?
I'm also experiencing an issue when loading a workbook and saving it again. The file is corrupted and everything in sheet 1 disappears.
UPDATE – example file: filewith2sheets.xlsx
When loading in an existing excel file (which has 2 sheets) using
wb <- loadWorkbook(targetFile)
everything goes well (print(wb)
shows that there are 2 sheets).However, when saving to the file using
saveWorkbook(wb, targetFile, overwrite = TRUE)
the resulting file cannot be opened.Even if I don't do anything to the
wb
object (likewriteData
), and just open (loadWorkbook()
) and close (saveWorkbook()
), the file gets corrupted.When I manually delete (in Excel) the second sheet from the excel file, save the file, and then run (from R) the open/close commands, all is well.
sessionInfo()