Share via


WorkbookBase.HasPassword 속성

통합 문서가 암호로 보호되어 있는지 여부를 나타내는 값을 가져옵니다.

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

구문

‘선언
Public ReadOnly Property HasPassword As Boolean
    Get
public bool HasPassword { get; }

속성 값

형식: System.Boolean
통합 문서가 암호로 보호되어 있으면 true이고, 그렇지 않으면 false입니다.

예제

다음 코드 예제에서는 HasPassword 속성의 값을 검사하여 통합 문서가 암호로 보호되는지 여부를 확인합니다. 통합 문서가 암호로 보호되지 않으면 예제에서는 Password 속성을 사용자 입력에서 가져온 암호로 설정한 다음 SetPasswordEncryptionOptions 메서드를 호출하여 암호화 알고리즘, 키 길이 및 암호화 공급자의 이름을 설정하고 파일 속성 암호화를 사용합니다. 그런 다음 예제에서는 PasswordEncryptionProvider, PasswordEncryptionAlgorithm, PasswordEncryptionKeyLengthPasswordEncryptionFileProperties 속성의 값을 워크시트 Sheet1에 표시합니다. 이 예제에서는 사용자 입력에서 강력한 암호를 가져오는 GetPasswordFromUserInput이라는 메서드가 있다고 가정합니다.

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

Private Sub WorkbookPasswordOptions()
    If Not Me.HasPassword Then
        Me.Password = GetPasswordFromUserInput()
        Me.SetPasswordEncryptionOptions( _
            "Microsoft RSA SChannel Cryptographic Provider", _
            "RC4", 128, True)
    End If

    ' Display the password properties in Sheet1.
    Globals.Sheet1.Range("A1").Value2 = _
        "Password Encryption Provider:"
    Globals.Sheet1.Range("A2").Value2 = _
        "Password Encryption Algorithm:"
    Globals.Sheet1.Range("A3").Value2 = _
        "Password Encryption Key Length:"
    Globals.Sheet1.Range("A4").Value2 = _
        "Password Encryption File Properties:"
    Globals.Sheet1.Range("A1", "A4").Columns.AutoFit()

    Globals.Sheet1.Range("B1").Value2 = _
        Me.PasswordEncryptionProvider
    Globals.Sheet1.Range("B2").Value2 = _
        Me.PasswordEncryptionAlgorithm
    Globals.Sheet1.Range("B3").Value2 = _
        Me.PasswordEncryptionKeyLength
    Globals.Sheet1.Range("B4").Value2 = _
        Me.PasswordEncryptionFileProperties
    Globals.Sheet1.Range("B1", "B4").Columns.AutoFit()
End Sub
private void WorkbookPasswordOptions()
{
    if (!this.HasPassword)
    {
        this.Password = GetPasswordFromUserInput();
        this.SetPasswordEncryptionOptions(
            "Microsoft RSA SChannel Cryptographic Provider",
            "RC4", 128, true);
    }

    // Display the password properties in Sheet1.
    Globals.Sheet1.Range["A1", missing].Value2 =
        "Password Encryption Provider:";
    Globals.Sheet1.Range["A2", missing].Value2 =
        "Password Encryption Algorithm:";
    Globals.Sheet1.Range["A3", missing].Value2 =
        "Password Encryption Key Length:";
    Globals.Sheet1.Range["A4", missing].Value2 =
        "Password Encryption File Properties:";
    Globals.Sheet1.Range["A1", "A4"].Columns.AutoFit();

    Globals.Sheet1.Range["B1", missing].Value2 =
        this.PasswordEncryptionProvider;
    Globals.Sheet1.Range["B2", missing].Value2 =
        this.PasswordEncryptionAlgorithm;
    Globals.Sheet1.Range["B3", missing].Value2 =
        this.PasswordEncryptionKeyLength;
    Globals.Sheet1.Range["B4", missing].Value2 =
        this.PasswordEncryptionFileProperties;
    Globals.Sheet1.Range["B1", "B4"].Columns.AutoFit();
}

.NET Framework 보안

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

참고 항목

참조

WorkbookBase 클래스

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