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


WorksheetBase.ProtectDrawingObjects - свойство

Возвращает значение, которое указывает на наличие защиты фигур в объекте.

Пространство имен:  Microsoft.Office.Tools.Excel
Сборка:  Microsoft.Office.Tools.Excel.v4.0.Utilities (в Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)

Синтаксис

'Декларация
Public ReadOnly Property ProtectDrawingObjects As Boolean
    Get
public bool ProtectDrawingObjects { get; }

Значение свойства

Тип: System.Boolean
Имеет значение true при наличии защиты фигур; в противном случае имеет значение false.

Примеры

В следующем примере путем обращения к свойству ProtectDrawingObjects программный код определяет, защищены ли фигуры рабочего листа. Если фигуры не защищены, для применения к ним защиты вызывается метод Protect, параметру DrawingObjects которого присвоено значение true.

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

    Private Sub ProtectShapes()
        If Not Me.ProtectDrawingObjects Then
            If DialogResult.Yes = MessageBox.Show("Shapes in this worksheet " & _
                "are not protected. Protect shapes the worksheet?", "Example", _
                MessageBoxButtons.YesNo) Then

                ' Protect shapes, but do not change any 
                ' other protection type.
                 Me.Protect(DrawingObjects:=True, _
                    Contents:=Me.ProtectContents, Scenarios:=Me.ProtectScenarios, _
                    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 'ProtectShapes

private void ProtectShapes()
{
    if (!this.ProtectDrawingObjects)
    {
        if (DialogResult.Yes == MessageBox.Show("Shapes in this worksheet " +
            "are not protected. Protect shapes the worksheet?", "Example", 
            MessageBoxButtons.YesNo))
        {
            // Protect shapes, but do not change any 
            // other protection type.
            this.Protect(missing, true, this.ProtectContents, 
                this.ProtectScenarios, 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

См. также

Ссылки

WorksheetBase Класс

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