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


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

Возвращает значение, которое указывает на наличие защиты содержимого рабочего листа (отдельных ячеек).

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

Синтаксис

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

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

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

Примеры

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

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

Private Sub ProtectCellContents()
    If Not Me.ProtectContents Then
        If DialogResult.Yes = MessageBox.Show("Cell contents in this " & _
            "worksheet are not protected. Protect cell contents?", "Example", _
            MessageBoxButtons.YesNo) Then

            ' Protect cell contents, but do not change any 
            ' other protection type.
            Me.Protect(DrawingObjects:=Me.ProtectDrawingObjects, _
                Contents:=True, 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
private void ProtectCellContents()
{
    if (!this.ProtectContents)
    {
        if (DialogResult.Yes == MessageBox.Show("Cell contents in this " +
            "worksheet are not protected. Protect cell contents?", "Example", 
            MessageBoxButtons.YesNo))
        {
            // Protect cell contents, but do not change any 
            // other protection type.
            this.Protect(missing, this.ProtectDrawingObjects,
                true, 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 - пространство имен