Поделиться через


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 программный код определяет, защищен ли пользовательский интерфейс. Если пользовательский интерфейс не защищен, для применения к нему защиты вызывается метод Protect, параметру UserInterfaceOnly которого присвоено значение true.

В этом примере демонстрируется настройка уровня документа.

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

См. также

Ссылки

WorksheetBase Класс

Microsoft.Office.Tools.Excel - пространство имен