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
)

Arguments

wb

A workbook object

sheet

A name or index of a worksheet

protect

Whether to protect or unprotect the sheet (default=TRUE)

password

(optional) password required to unprotect the worksheet

lockSelectingLockedCells

Whether selecting locked cells is locked

lockSelectingUnlockedCells

Whether selecting unlocked cells is locked

lockFormattingCells

Whether formatting cells is locked

lockFormattingColumns

Whether formatting columns is locked

lockFormattingRows

Whether formatting rows is locked

lockInsertingColumns

Whether inserting columns is locked

lockInsertingRows

Whether inserting rows is locked

lockInsertingHyperlinks

Whether inserting hyperlinks is locked

lockDeletingColumns

Whether deleting columns is locked

lockDeletingRows

Whether deleting rows is locked

lockSorting

Whether sorting is locked

lockAutoFilter

Whether auto-filter is locked

lockPivotTables

Whether pivot tables are locked

lockObjects

Whether objects are locked

lockScenarios

Whether scenarios are locked

Author

Reinhold Kainhofer

Examples

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) { saveWorkbook(wb, "pageSetupExample.xlsx", overwrite = TRUE) }