Udostępnij za pośrednictwem


Właściwość WorksheetBase.ProtectionMode —

Pobiera wartość, która wskazuje, czy włączona jest ochrona tylko do interfejsu użytkownika.

Przestrzeń nazw:  Microsoft.Office.Tools.Excel
Zestaw:  Microsoft.Office.Tools.Excel.v4.0.Utilities (w Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)

Składnia

'Deklaracja
Public ReadOnly Property ProtectionMode As Boolean
public bool ProtectionMode { get; }

Wartość właściwości

Typ: System.Boolean
true Jeśli włączono ochronę tylko do interfejsu użytkownika; w przeciwnym razie false.

Uwagi

Aby włączyć funkcję ochrony interfejsu użytkownika, należy użyć Protect metody z UserInterfaceOnly argument wartość true.

Przykłady

Poniższy przykład kodu pobiera wartość ProtectionMode właściwość w celu określenia, czy interfejs użytkownika jest chroniony.Jeśli interfejs użytkownika jest niezabezpieczone, a następnie Protect metoda jest wywoływana z UserInterfaceOnly wartość parametru równa true tak, że interfejs użytkownika jest chroniony.

Ten przykład dotyczy dostosowywania poziomie dokumentu.

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(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);
        }
    }
}

Zabezpieczenia programu .NET Framework

Zobacz też

Informacje

WorksheetBase Klasa

Przestrzeń nazw Microsoft.Office.Tools.Excel