Share via


WorksheetBase.Protect 메서드

워크시트를 수정할 수 없도록 보호합니다.

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

구문

‘선언
Public Sub Protect ( _
    password As Object, _
    drawingObjects As Object, _
    contents As Object, _
    scenarios As Object, _
    userInterfaceOnly As Object, _
    allowFormattingCells As Object, _
    allowFormattingColumns As Object, _
    allowFormattingRows As Object, _
    allowInsertingColumns As Object, _
    allowInsertingRows As Object, _
    allowInsertingHyperlinks As Object, _
    allowDeletingColumns As Object, _
    allowDeletingRows As Object, _
    allowSorting As Object, _
    allowFiltering As Object, _
    allowUsingPivotTables As Object _
)
public void Protect(
    Object password,
    Object drawingObjects,
    Object contents,
    Object scenarios,
    Object userInterfaceOnly,
    Object allowFormattingCells,
    Object allowFormattingColumns,
    Object allowFormattingRows,
    Object allowInsertingColumns,
    Object allowInsertingRows,
    Object allowInsertingHyperlinks,
    Object allowDeletingColumns,
    Object allowDeletingRows,
    Object allowSorting,
    Object allowFiltering,
    Object allowUsingPivotTables
)

매개 변수

  • password
    형식: System.Object
    워크시트의 대/소문자 구분 암호입니다.이 인수를 생략하면 암호를 사용하지 않고 워크시트의 보호를 해제할 수 있습니다.그렇지 않으면 암호를 지정해야 워크시트의 보호를 해제할 수 있습니다.암호를 잊어버리면 워크시트의 보호를 해제할 수 없습니다.암호 목록과 해당하는 문서 이름을 안전한 곳에 보관하는 것이 좋습니다.
  • drawingObjects
    형식: System.Object
    도형을 보호하려면 true입니다.기본값은 false입니다.
  • contents
    형식: System.Object
    잠긴 셀의 내용을 보호하려면 true입니다.기본값은 true입니다.
  • scenarios
    형식: System.Object
    시나리오를 보호하려면 true입니다.기본값은 true입니다.
  • userInterfaceOnly
    형식: System.Object
    매크로가 아니라 사용자 인터페이스를 보호하려면 true입니다.이 인수를 생략하면 매크로와 사용자 인터페이스 모두에 보호가 적용됩니다.
  • allowFormattingCells
    형식: System.Object
    보호된 워크시트의 셀에 서식을 지정할 수 있도록 하려면 true입니다.기본값은 false입니다.
  • allowFormattingColumns
    형식: System.Object
    보호된 워크시트의 열에 서식을 지정할 수 있도록 하려면 true입니다.기본값은 false입니다.
  • allowFormattingRows
    형식: System.Object
    보호된 워크시트의 행에 서식을 지정할 수 있도록 하려면 true입니다.기본값은 false입니다.
  • allowInsertingColumns
    형식: System.Object
    보호된 워크시트에 열을 삽입할 수 있도록 하려면 true입니다.기본값은 false입니다.
  • allowInsertingRows
    형식: System.Object
    보호된 워크시트에 행을 삽입할 수 있도록 하려면 true입니다.기본값은 false입니다.
  • allowInsertingHyperlinks
    형식: System.Object
    워크시트에 하이퍼링크를 삽입할 수 있도록 하려면 true입니다.기본값은 false입니다.
  • allowDeletingColumns
    형식: System.Object
    보호된 워크시트의 열을 삭제할 수 있도록 하려면 true입니다. 삭제되는 열의 셀은 모두 잠금 해제됩니다.기본값은 false입니다.
  • allowDeletingRows
    형식: System.Object
    보호된 워크시트의 행을 삭제할 수 있도록 하려면 true입니다. 삭제되는 행의 셀은 모두 잠금 해제됩니다.기본값은 false입니다.
  • allowSorting
    형식: System.Object
    보호된 워크시트에서 정렬할 수 있도록 하려면 true입니다.정렬 범위의 모든 셀은 잠금 또는 보호가 해제되어 있어야 합니다.기본값은 false입니다.
  • allowFiltering
    형식: System.Object
    보호된 워크시트에 필터를 설정할 수 있도록 하려면 true입니다.사용자가 필터 조건을 변경할 수 있지만 자동 필터를 설정하거나 해제할 수는 없습니다.사용자는 기존 자동 필터에서 필터를 설정할 수 있습니다.기본값은 false입니다.
  • allowUsingPivotTables
    형식: System.Object
    보호된 워크시트에서 피벗 테이블 보고서를 사용할 수 있도록 하려면 true입니다.기본값은 false입니다.

설명

UserInterfaceOnly 인수를 true로 설정하여 이 메서드를 적용한 다음 통합 문서를 저장하면 해당 통합 문서를 다시 열 때 인터페이스뿐만 아니라 전체 워크시트가 완전히 보호됩니다. 통합 문서를 연 후에 사용자 인터페이스 보호를 다시 설정하려면 UserInterfaceOnly를 true로 설정하여 이 메서드를 다시 적용해야 합니다.

암호를 제공하면 보호된 워크시트를 변경할 수 있습니다. 또한 다른 메서드로 워크시트의 보호를 해제하고 필요한 사항을 변경한 다음 워크시트를 다시 보호할 수 있습니다.

참고

셀 서식 대화 상자의 '보호 취소됨'은 셀이 잠겨 있지만 범위 편집 허용 대화 상자에 정의된 범위에 포함된 경우와, 사용자가 암호를 사용하여 범위 보호를 해제했거나 NT 사용 권한을 통해 유효화된 경우를 의미합니다.

선택적 매개 변수

선택적 매개 변수에 대한 자세한 내용은 Office 솔루션의 선택적 매개 변수를 참조하십시오.

예제

다음 코드 예제에서는 ProtectContents 속성의 값을 가져와 워크시트의 내용이 보호되어 있는지 여부를 확인합니다. 내용이 보호되어 있지 않으면 Contents 매개 변수를 true로 설정하여 Protect 메서드를 호출함으로써 내용을 보호합니다.

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

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 네임스페이스