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
Get
public bool ProtectScenarios { get; }
屬性值
型別:System.Boolean
如果工作表分析藍本受到保護,則為 true,否則為 false。
範例
下列程式碼範例會取得 ProtectScenarios 屬性的值,判斷工作表分析藍本是否受到保護。 如果分析藍本未受到保護,就會呼叫 Protect 方法,並將這個方法的 Scenarios 參數設定為 true,分析藍本就會受到保護。
這是示範文件層級自訂的範例。
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(missing, 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 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。