3

I want to password protect this dataframe that I have created in R and I tried using protectWorkbook() function from openxlsx and it does not work, I am still able to open the excel normally without entering password.

df = data.frame(Year = c(2018,2019,2020,2018,2019,2020,2018,2019,2020),
                Country = c("Germany","Germany","Germany", "Japan", "Japan", "Japan",  "Thailand", "Thailand", "Thailand"), 
                Count = c(17, 15, 60, 23, 25, 60, 50, 18, 31))

wb = createWorkbook()
addWorksheet(wb, "Master")
writeDataTable(wb, "Master", df, tableStyle = "TableStyleLight9")
yellow_style = createStyle(fgFill = "#FFFF00")
y = which(colnames(df) == "Count")
x = which(abs(df$Count) > 32)
addStyle(wb, sheet = "Master", style = yellow_style, rows = x+1, col = y)
protectWorkbook(wb, protect = TRUE, password = "Password", lockStructure = TRUE)
saveWorkbook(wb, "Master.xlsx", overwrite = TRUE)

#xl.save.file(wb, "Master2.xlsx", password = "Pass")

I tried using xl.save.file from excel.link library but my Rstudio crashes

zx8754
  • 52,746
  • 12
  • 114
  • 209
realbeast91
  • 176
  • 9
  • 1
    looks like an issue. I've tried to use the github version of the package but it shows the same problem. Submit your issue here: https://github.com/awalker89/openxlsx/issues – Edo Nov 30 '20 at 09:33
  • [This](https://stackoverflow.com/questions/37991389/r-save-a-excel-workbook-with-password-protection) Might help. – Shamis Nov 30 '20 at 09:42

0 Answers0