Skip to main content

Метод Table.setProtection

Метод устанавливает защиту от изменений на лист табличного документа (см. Защита листа табличного документа).

Вызов​


public void setProtection(TableProtectionProperties tableProtectionProperties, string password)

Параметры​

  • tableProtectionProperties: параметры защиты листа, тип TableProtectionProperties;
  • password: (необязательный) пароль для установки защиты, тип string.

Пример​


TableProtectionProperties tableProps = new TableProtectionProperties();
tableProps.deleteColumns = false;
tableProps.deleteRows = false;
tableProps.filterData = true;
tableProps.formatCells = true;
tableProps.formatColumns = true;
tableProps.formatRows = true;
tableProps.insertAndEditObjects = false;
tableProps.insertAndEditPivotTables = false;
tableProps.insertColumns = false;
tableProps.insertLinks = true;
tableProps.insertRows = false;
tableProps.selectProtectedCells = true;
tableProps.sortData = true;

Table firstSheet = document.getBlocks().getTable(0);
firstSheet.setProtection(tableProps, "password");

Метод setProtectionProperties() объектов Cell и CellRange позволяет задать параметры защиты для ячеек (например, разрешить редактирование определенных ячеек в документе перед установкой защиты).

Если метод setProtection() применяется к уже защищенному листу, возникает исключение SpreadsheetProtectionError.