【发布时间】:2021-09-23 07:42:01
【问题描述】:
我想用密码保护我正在使用特定工作流程创建的大量 .xslx 文件。工作流程很简单,并且依赖于我使用 R 中 openxlsx 中的 write.xlsx 命令编写的较小数据帧的命名列表。是否有解决方案可以使用类似的工作流程使用 protectWorkbook 密码保护这些文件?谢谢。
library(tidyverse)
library(openxlsx)
## Create reprex using diamonds
df_ls <- diamonds %>%
select_if(is.ordered) %>%
gather(key, value) %>%
split(.$key)
#> Warning: attributes are not identical across measure variables;
#> they will be dropped
## I like to use lists to write to .xlsx
## because write.xlsx creates each object
## in the list as its own sheet and names
## it using the list names.
.path <- tempfile(fileext = ".xlsx")
write.xlsx(df_ls, file = .path)
## I want to password protect this file(s)
map(.path, ~{protectWorkbook(.x, protect = TRUE, password = "random-password")})
# Error in protectWorkbook(.x, protect = TRUE, password = "random-password") :
# First argument must be a Workbook.
由reprex package (v2.0.0) 于 2021-07-14 创建
【问题讨论】:
标签: r excel password-protection openxlsx