I have exported my dataframe according to their respective filter, in this case, its the Country
df = data.frame(Country = c("Japan", "Japan", "Thailand", "Germany", "Thailand", "Japan"),
Count = c(15, 5, 25, 5, 60, 50))
#Separate the dataframe according to their respective country
splitdf = split(df, df$Country)
#apply style and export
save_data <- function(df, name) {
wb <- createWorkbook()
addWorksheet(wb, name)
writeDataTable(wb, name, df, tableStyle = "TableStyleMedium2")
saveWorkbook(wb, paste0(name, ".xlsx"), overwrite = TRUE)
}
mapply(
save_data,
splitdf,
names(splitdf)
)
Now, the 3 xlsx are stored in a folder in my working directory with their workbook name being the Country they have been filtered by. I would like to Password protect them in such a way that it will be a fixed string, "iLove" + first 2 character of their file name.
Example, the password for Workbook "Japan" will be "iLoveJa" and Germany will be "iLoveGe"