WorksheetBase.ProtectScenarios 属性

获取一个值,该值指示工作表方案是否受保护。

命名空间:  Microsoft.Office.Tools.Excel
程序集:  Microsoft.Office.Tools.Excel.v4.0.Utilities(在 Microsoft.Office.Tools.Excel.v4.0.Utilities.dll 中)

语法

声明
Public ReadOnly Property ProtectScenarios As Boolean
public bool ProtectScenarios { get; }

属性值

类型:System.Boolean
如果工作表方案受保护,则为 true;否则为 false。

示例

下面的代码示例获取 ProtectScenarios 属性的值,以确定工作表方案是否受保护。 如果方案不受保护,则将 Scenarios 参数设置为 true 来调用 Protect 方法,以使方案受保护。

此示例针对的是文档级自定义项。

Private Sub SetScenarioProtectionOn()
    If Not Me.ProtectScenarios Then
        If DialogResult.Yes = MessageBox.Show("Scenario protection is " & _
            "turned off. Turn on scenario protection?", "Example", _
            MessageBoxButtons.YesNo) Then

            ' Enable scenario protection, but do not change 
            ' any other protection type.
            Me.Protect(DrawingObjects:=Me.ProtectDrawingObjects, _
                Contents:=Me.ProtectContents, Scenarios:=True, _
                UserInterfaceOnly:=Me.ProtectionMode, _
                AllowFormattingCells:=Me.Protection.AllowFormattingCells, _
                AllowFormattingColumns:=Me.Protection.AllowFormattingColumns, _
                AllowFormattingRows:=Me.Protection.AllowFormattingRows, _
                AllowInsertingColumns:=Me.Protection.AllowInsertingColumns, _
                AllowInsertingRows:=Me.Protection.AllowInsertingRows, _
                AllowInsertingHyperlinks:=Me.Protection.AllowInsertingHyperlinks, _
                AllowDeletingColumns:=Me.Protection.AllowDeletingColumns, _
                AllowDeletingRows:=Me.Protection.AllowDeletingRows, _
                AllowSorting:=Me.Protection.AllowSorting, _
                AllowFiltering:=Me.Protection.AllowFiltering, _
                AllowUsingPivotTables:=Me.Protection.AllowUsingPivotTables)
        End If
    End If
End Sub
private void SetScenarioProtectionOn()
{
    if (!this.ProtectScenarios)
    {
        if (DialogResult.Yes == MessageBox.Show("Scenario protection is " +
            "turned off. Turn on scenario protection?", "Example",
            MessageBoxButtons.YesNo))
        {
            // Enable scenario protection, but do not change 
            // any other protection type.
            this.Protect(this.ProtectDrawingObjects,
                this.ProtectContents, true, this.ProtectionMode, 
                this.Protection.AllowFormattingCells,
                this.Protection.AllowFormattingColumns,
                this.Protection.AllowFormattingRows,
                this.Protection.AllowInsertingColumns,
                this.Protection.AllowInsertingRows,
                this.Protection.AllowInsertingHyperlinks,
                this.Protection.AllowDeletingColumns,
                this.Protection.AllowDeletingRows,
                this.Protection.AllowSorting,
                this.Protection.AllowFiltering,
                this.Protection.AllowUsingPivotTables);
        }
    }
}

.NET Framework 安全性

请参见

参考

WorksheetBase 类

Microsoft.Office.Tools.Excel 命名空间