Write a docx and password protect it

72 views Asked by At

I use ReporteRs package to generate a report. I am wondering whether there is any option to provide a password to protect the document? If anyone encountered this issue that they want to write a report & protect them using a password.

How did you manage to put a password to your report?

1

There are 1 answers

0
Emmanuel Hamel On

The following approach can be considered :

library(RDCOMClient)
wordApp <- COMCreate("Word.Application")
wordApp[["Visible"]] <- TRUE
wordApp[["DisplayAlerts"]] <- FALSE
path_To_Word_File <- "D:\\text_No_Password.docx"
doc <- wordApp[["Documents"]]$Open(normalizePath(path_To_Word_File), ConfirmConversions = FALSE)
doc$SaveAs("D:\\text_With_Password.docx", password = "123")