Share via


WorksheetBase.Protection 속성

워크시트의 보호 옵션을 나타내는 Microsoft.Office.Interop.Excel.Protection 개체를 가져옵니다.

네임스페이스:  Microsoft.Office.Tools.Excel
어셈블리:  Microsoft.Office.Tools.Excel.v4.0.Utilities(Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)

구문

‘선언
Public ReadOnly Property Protection As Protection
    Get
public Protection Protection { get; }

속성 값

형식: Microsoft.Office.Interop.Excel.Protection
워크시트의 보호 옵션을 나타내는 Microsoft.Office.Interop.Excel.Protection 개체입니다.

예제

다음 코드 예제에서는 Protection 속성의 값을 가져와 현재 셀 서식이 허용되는지 여부를 확인합니다. 셀 서식이 허용되지 않는 경우 셀 서식을 지정할 수 있도록 true로 설정된 AllowFormattingCells 매개 변수를 사용하여 Protect 메서드가 호출됩니다.

이 예제는 문서 수준 사용자 지정을 위한 것입니다.

Private Sub ProtectCellFormatting()

    ' Protect cell contents, but do not change any 
    ' other protection type. This enables the Protection
    ' property to have effect.
    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)

    If Not Me.Protection.AllowFormattingCells Then
        If DialogResult.Yes = MessageBox.Show("Formatting cells is " & _
            "not allowed. Allow formatting cells?", "Example", _
            MessageBoxButtons.YesNo) Then

            ' Allow cell formatting, but do not change any other protection type.
            Me.Protect(DrawingObjects:=Me.ProtectDrawingObjects, _
                Contents:=Me.ProtectContents, Scenarios:=Me.ProtectScenarios, _
                UserInterfaceOnly:=Me.ProtectionMode, _
                AllowFormattingCells:=True, _
                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 ProtectCellFormatting()
{
    // Protect cell contents, but do not change any 
    // other protection type. This enables the Protection
    // property to have effect.
    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);

    if (!this.Protection.AllowFormattingCells)
    {
        if (DialogResult.Yes == MessageBox.Show("Formatting cells is " +
            "not allowed. Allow formatting cells?", "Example", 
            MessageBoxButtons.YesNo))
        {
            // Allow cell formatting, but do not change any other protection type.
            this.Protect(missing, this.ProtectDrawingObjects, 
                this.ProtectContents, this.ProtectScenarios, 
                this.ProtectionMode, true, 
                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 네임스페이스