Protect or unprotect a worksheet from modifications by the user in the graphical user interface. Replaces an existing protection.
protectWorksheet(
wb,
sheet,
protect = TRUE,
password = NULL,
lockSelectingLockedCells = NULL,
lockSelectingUnlockedCells = NULL,
lockFormattingCells = NULL,
lockFormattingColumns = NULL,
lockFormattingRows = NULL,
lockInsertingColumns = NULL,
lockInsertingRows = NULL,
lockInsertingHyperlinks = NULL,
lockDeletingColumns = NULL,
lockDeletingRows = NULL,
lockSorting = NULL,
lockAutoFilter = NULL,
lockPivotTables = NULL,
lockObjects = NULL,
lockScenarios = NULL
)
A workbook object
A name or index of a worksheet
Whether to protect or unprotect the sheet (default=TRUE)
(optional) password required to unprotect the worksheet
Whether selecting locked cells is locked
Whether selecting unlocked cells is locked
Whether formatting cells is locked
Whether formatting columns is locked
Whether formatting rows is locked
Whether inserting columns is locked
Whether inserting rows is locked
Whether inserting hyperlinks is locked
Whether deleting columns is locked
Whether deleting rows is locked
Whether sorting is locked
Whether auto-filter is locked
Whether pivot tables are locked
Whether objects are locked
Whether scenarios are locked
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
)
# Remove the protection
protectWorksheet(wb, "S1", protect = FALSE)
if (FALSE) { # \dontrun{
saveWorkbook(wb, "pageSetupExample.xlsx", overwrite = TRUE)
} # }