1

我正在使用 excel 模板从不同的人那里收集数据。为了尽量减少人们更改模板结构的机会,我想保护工作表,但仍允许他们填写我想要的数据值。

我很高兴我找到了一个分叉版本的 openxlsx 包,其中包含一个功能protectWorksheet,即Link。但是当我使用该功能时,我无法调整该功能以便仍然可以填充值。

除了帮助文件中示例中的功能外,我真的没有 MWE 。如何调整示例以仍然允许填写值?可能吗?

wb <- createWorkbook()
addWorksheet(wb, "S1")
writeDataTable(wb, 1, x = iris[1:30,])
# Formatting cells / columns is allowed , but inserting / deleting columns is protected:
protectWorksheet(wb, "S1", protect = TRUE, lockFormattingCells = FALSE, lockFormattingColumns = FALSE, lockInsertingColumns = TRUE, lockDeletingColumns = TRUE)

saveWorkbook(wb, "pageSetupExample.xlsx", overwrite = TRUE)
4

1 回答 1

4

感谢@Reinhold Kainhofer,您可以使用createStyle.

openxlsx从 github下载包: https ://github.com/kainhofer/openxlsx 。

wb <- createWorkbook()
addWorksheet(wb, "S1")
writeDataTable(wb, 1, x = iris[1:30,])
# Formatting cells / columns is allowed , but inserting / deleting columns is protected:
protectWorksheet(wb, "S1", protect = TRUE, lockFormattingCells = FALSE, lockFormattingColumns = FALSE, lockInsertingColumns = TRUE, lockDeletingColumns = TRUE)

#This line allows specified cells to be unlocked so that users can enter values.
addStyle(wb, "S1", style = createStyle(locked = FALSE), rows = 1:10, cols = 1)

saveWorkbook(wb, "pageSetupExample.xlsx", overwrite = TRUE)
于 2019-05-10T00:50:23.153 回答