I'd like to be able to load an Excel file with hidden worksheets and have them stay hidden when I write the file back out again.
Relatedly, the sheetVisibility function is not allowing me to hide worksheets. I have 8 worksheets and would expect to be able to hide 2 of them.
Actual Behavior
If I hide the sheets in the original Excel file, they become unhidden when I load the workbook. If I try to hide them using sheetVisibility, I get an warning saying "Warning message: In value != exState : longer object length is not a multiple of shorter object length." When I save the workbook and open it in Excel, the worksheet I tried to hide is completely gone (and I'm not using "veryHidden").
I think it might be related to the fact that the workbook has xml charts and there are cell references across different worksheets. If I don't write any data to the file, but rather load, set sheetVisibility, and save, I am able to use sheetVisibility successfully.
Expected Behavior
I'd like to be able to load an Excel file with hidden worksheets and have them stay hidden when I write the file back out again. Relatedly, the sheetVisibility function is not allowing me to hide worksheets. I have 8 worksheets and would expect to be able to hide 2 of them.
Actual Behavior
If I hide the sheets in the original Excel file, they become unhidden when I load the workbook. If I try to hide them using sheetVisibility, I get an warning saying "Warning message: In value != exState : longer object length is not a multiple of shorter object length." When I save the workbook and open it in Excel, the worksheet I tried to hide is completely gone (and I'm not using "veryHidden").
I think it might be related to the fact that the workbook has xml charts and there are cell references across different worksheets. If I don't write any data to the file, but rather load, set sheetVisibility, and save, I am able to use sheetVisibility successfully.
Steps to Reproduce the Problem
(please attach an example xlsx file if possible)
wb <- loadWorkbook("~/R training/templates/template_production_sample.xlsx")
Run code that writes data and cell formatting to the workbook (there are 8 worksheets total)
sheetVisibility(wb)[7]<- "hidden" sheetVisibility(wb)[8]<- "hidden" Receive warning message
saveWorkbook(wb, paste0("~/R training/templates/template_productiontest", i, ".xlsx"), overwrite = T)
Open workbook in Excel and worksheets 7 and 8 are gone and all of the charts referencing data in those cells are blank.
template_production_sample.xlsx
sessionInfo()