WorksheetBase.ProtectionMode 属性
获取一个值,该值指示是否打开仅限用户界面保护。
命名空间: Microsoft.Office.Tools.Excel
程序集: Microsoft.Office.Tools.Excel.v4.0.Utilities(在 Microsoft.Office.Tools.Excel.v4.0.Utilities.dll 中)
语法
声明
Public ReadOnly Property ProtectionMode As Boolean
Get
public bool ProtectionMode { get; }
属性值
类型:System.Boolean
如果打开仅限用户界面保护,则为 true;否则为 false。
备注
若要开启用户界面保护,请使用 Protect 方法,并将其 UserInterfaceOnly 参数设置为 true。
示例
下面的代码示例获取 ProtectionMode 属性的值,以确定用户界面是否受保护。 如果用户界面不受保护,则将 UserInterfaceOnly 参数设置为 true 来调用 Protect 方法,以使用户界面受保护。
此示例针对的是文档级自定义项。
Private Sub ProtectUserInterface()
If Not Me.ProtectionMode Then
If DialogResult.Yes = MessageBox.Show("User interface protection is " & _
"turned off. Turn on user interface protection?", "Example", _
MessageBoxButtons.YesNo) Then
' Enable user interface protection, but do not change
' any other protection type.
Me.Protect(DrawingObjects:=Me.ProtectDrawingObjects, _
Contents:=Me.ProtectContents, Scenarios:=Me.ProtectScenarios, _
UserInterfaceOnly:=True, _
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 ProtectUserInterface()
{
if (!this.ProtectionMode)
{
if (DialogResult.Yes == MessageBox.Show("User interface protection is " +
"turned off. Turn on user interface protection?", "Example",
MessageBoxButtons.YesNo))
{
// Enable user interface protection, but do not change
// any other protection type.
this.Protect(missing, this.ProtectDrawingObjects,
this.ProtectContents, this.ProtectScenarios,
true, 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 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。