0

Is there a way to password protect a a group of excel files.

I have written an R script that generates about 50 excel reports. They contain sensitive information and need to be password protected before I can them to customers.

How can I automate the password protection? an R solution would be preferable but I will try anything.

  • I've never used R so not sure how you save these reports. But if R anything like VBA (or if you are creating an excel instance), you have an option to add password to a workbook when you save it. Is that not an option? – Zac Jul 31 '17 at 14:31
  • 4
    the solution is here https://stackoverflow.com/questions/37991389/r-save-a-excel-workbook-with-password-protection – s.brunel Jul 31 '17 at 14:35
  • That solution only works with the xlsx package and I have a lengthy script written with the openxlsx package. I was aware of that solution and I am searching for a different one – Michael Ricci Jul 31 '17 at 17:20

1 Answers1

0

You can use the following approach to add a password to an Excel file. This approach only works on Windows.

library(RDCOMClient)

path_Excel_File1 <- "D:\\file_No_Password.xlsx"
path_Excel_File2 <- "D:\\file_With_Password.xlsx"

xlApp <- COMCreate("Excel.Application")
xlApp[["Visible"]] <- TRUE
xlWbk <- xlApp$Workbooks()$Open(path_Excel_File1)

xlWbk$SaveAs(path_Excel_File2, password = "hi 123")
xlWbk$Close()
Emmanuel Hamel
  • 1,769
  • 7
  • 19