Skip to content
本页内容

Protection (对象)

代表工作表可使用的各种保护选项类型。

说明

使用 Worksheet 对象的 Protection 属性可返回一个 Protection 对象。

返回一个 Protection 对象后,就可用该对象的下列属性来设置或返回保护选项。

  • AllowDeletingColumns
  • AllowDeletingRows
  • AllowFiltering
  • AllowFormattingCells
  • AllowFormattingColumns
  • AllowFormattingRows
  • AllowInsertingColumns
  • AllowInsertingHyperlinks
  • AllowInsertingRows
  • AllowSorting
  • AllowUsingPivotTables

示例

python
#下例通过在最上面的行中放三个成员并保留该工作表说明了如何使用 Protection 对象的 AllowInsertingColumns 属性。然后,此示例检查允许插入列的保护设置是否为 False ,并在必要时将其设置为 True。最后,通知用户插入一个列
def test():
    Range("A1").Formula = "1"
    Range("B1").Formula = "3"
    Range("C1").Formula = "4"
    ActiveSheet.Protect()
    # Check the protection setting of the worksheet and act accordingly.
    if Application.ActiveSheet.Protection.AllowInsertingColumns == False:
        Application.ActiveSheet.Protect(None, None, None, None, None, None, None, None, True)
        print("Insert a column between 1 and 3")
    else:
        print("Insert a column between 1 and 3")
python
#本示例显示是否允许在受保护的第二张工作表上插入列
def test():
    print(Worksheets.Item(2).Protection.AllowInsertingColumns)