Compartir a través de


WorksheetBase.ProtectionMode (Propiedad)

Obtiene un valor que indica si está activada la protección de sólo interfaz de usuario.

Espacio de nombres:  Microsoft.Office.Tools.Excel
Ensamblado:  Microsoft.Office.Tools.Excel.v4.0.Utilities (en Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)

Sintaxis

'Declaración
Public ReadOnly Property ProtectionMode As Boolean
    Get
public bool ProtectionMode { get; }

Valor de propiedad

Tipo: System.Boolean
true si está activada la protección de sólo interfaz de usuario; de lo contrario, false.

Comentarios

Para activar la protección de la interfaz de usuario, utilice el método Protect con el argumento UserInterfaceOnly establecido en true.

Ejemplos

El ejemplo de código siguiente obtiene el valor de la propiedad ProtectionMode para determinar si la interfaz de usuario está protegida. Si la interfaz de usuario no está protegida, se llama al método Protect con el parámetro UserInterfaceOnly establecido en true para proteger la interfaz de usuario.

Se trata de un ejemplo para una personalización en el nivel del documento.

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

Seguridad de .NET Framework

Vea también

Referencia

WorksheetBase Clase

Microsoft.Office.Tools.Excel (Espacio de nombres)