WorkbookBase.ProtectDocument 메서드

캐시된 데이터가 저장된 후 통합 문서에 암호 보호를 다시 적용할 수 있도록 Microsoft Visual Studio Tools for Office Runtime에서 호출합니다.

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

구문

‘선언
Protected Overridable Sub ProtectDocument
protected virtual void ProtectDocument()

설명

통합 문서가 암호를 사용하여 보호되어 있고 이 통합 문서에 런타임에 변경될 수 있는 캐시된 데이터가 들어 있는 경우 Excel용 문서 수준 프로젝트에서 이 메서드를 재정의합니다.이 메서드를 구현할 때는 Protect 메서드를 사용하여 통합 문서를 보호합니다.

기본적으로 암호로 보호된 통합 문서의 캐시된 데이터에 대한 변경 사항은 통합 문서가 저장될 때 유지되지 않습니다.캐시된 데이터의 변경 사항을 저장하려면 프로젝트에서 다음 메서드를 재정의해야 합니다.

  • UnprotectDocument.통합 문서가 저장되면 Microsoft Visual Studio Tools for Office Runtime에서 이 메서드를 호출합니다.이 메서드에 통합 문서의 보호를 임시로 해제하는 코드를 추가합니다.이를 통해 캐시된 데이터의 변경 사항을 저장할 수 있습니다.

  • ProtectDocument.통합 문서가 저장된 후 Microsoft Visual Studio Tools for Office Runtime에서 이 메서드를 호출합니다.이 메서드에 통합 문서에 보호를 다시 적용하는 코드를 추가합니다.

자세한 내용은 방법: 암호로 보호된 문서의 데이터 캐시을 참조하십시오.

암호 보호와 관련이 없는 오류로 인해 캐시된 데이터를 저장할 수 없는 경우에도 Microsoft Visual Studio Tools for Office Runtime에서는 ProtectDocument 메서드를 호출합니다.예를 들어 ICachedType 인터페이스를 구현하여 캐시된 데이터가 문서에 저장되는 방식을 사용자 지정하는 경우, ICachedType 구현에서 캐시된 데이터를 저장할 수 없게 하는 예외가 throw되더라도 ProtectDocument 메서드가 호출됩니다.

예제

다음 코드 예제에서는 ProtectDocument 메서드를 재정의하여 UnprotectDocument 메서드 재정의를 통해 해제된 보호를 다시 적용하는 방법을 보여 줍니다.이 코드를 사용하려면 Excel용 문서 수준 프로젝트의 ThisWorkbook 클래스에서 코드를 실행합니다.이 코드에서는 암호가 securelyStoredPassword라는 필드에 저장되어 있다고 가정합니다.

<CachedAttribute()> _
Public CachedString As String = "This string is cached in the workbook."

Private protectStructureValue As Boolean
Private protectWindowsValue As Boolean

Protected Overrides Sub UnprotectDocument()
    protectStructureValue = Me.ProtectStructure
    protectWindowsValue = Me.ProtectWindows

    Me.Unprotect(securelyStoredPassword)
End Sub

Protected Overrides Sub ProtectDocument()
    Me.Protect(securelyStoredPassword, protectStructureValue, _
        protectWindowsValue)
End Sub
[CachedAttribute]
public string CachedString = "This string is cached in the workbook.";

private bool protectStructureValue;
private bool protectWindowsValue;

protected override void UnprotectDocument()
{
    protectStructureValue = this.ProtectStructure;
    protectWindowsValue = this.ProtectWindows;

    this.Unprotect(securelyStoredPassword);
}

protected override void ProtectDocument()
{
    this.Protect(securelyStoredPassword, protectStructureValue,
        protectWindowsValue);
}

.NET Framework 보안

  • 직접 실행 호출자의 경우 완전히 신뢰합니다. 이 멤버는 부분적으로 신뢰할 수 있는 코드에서 사용할 수 없습니다. 자세한 내용은 부분 신뢰 코드에서 라이브러리 사용을 참조하십시오.

참고 항목

참조

WorkbookBase 클래스

Microsoft.Office.Tools.Excel 네임스페이스

UnprotectDocument

기타 리소스

데이터 캐싱

방법: 암호로 보호된 문서의 데이터 캐시