WorkbookBase.SetPasswordEncryptionOptions 方法
設定使用密碼加密活頁簿的選項。
命名空間: Microsoft.Office.Tools.Excel
組件: Microsoft.Office.Tools.Excel.v4.0.Utilities (在 Microsoft.Office.Tools.Excel.v4.0.Utilities.dll 中)
語法
'宣告
Public Sub SetPasswordEncryptionOptions ( _
passwordEncryptionProvider As Object, _
passwordEncryptionAlgorithm As Object, _
passwordEncryptionKeyLength As Object, _
passwordEncryptionFileProperties As Object _
)
public void SetPasswordEncryptionOptions(
Object passwordEncryptionProvider,
Object passwordEncryptionAlgorithm,
Object passwordEncryptionKeyLength,
Object passwordEncryptionFileProperties
)
參數
- passwordEncryptionProvider
型別:System.Object
區分大小寫的加密提供者字串。
- passwordEncryptionAlgorithm
型別:System.Object
區分大小寫的演算法簡短名稱字串 (即 "RC4")。..
- passwordEncryptionKeyLength
型別:System.Object
加密金鑰長度,為 8 的倍數 (40 或更大)。
- passwordEncryptionFileProperties
型別:System.Object
true (預設) 表示加密檔案屬性。
備註
PasswordEncryptionProvider、PasswordEncryptionAlgorithm 和 PasswordEncryptionKeyLength 參數彼此不獨立存在。選取的加密提供者會限制可選擇的演算法和金鑰長度設定。
如果是 PasswordEncryptionKeyLength 參數,則金鑰長度範圍就沒有固定的限制。密碼編譯服務提供者會決定範圍,同時也決定密碼編譯演算法。
選擇性參數
如需選擇性參數的詳細資訊,請參閱Office 方案中的選擇性參數。
範例
下列程式碼範例檢查 HasPassword 屬性的值,判斷活頁簿是否已設定密碼保護。如果活頁簿未設定密碼保護,則此範例會將 Password 屬性設為使用者輸入的密碼,然後呼叫 SetPasswordEncryptionOptions 方法,設定加密 (Encryption) 演算法、金鑰 (Key) 長度、加密提供者名稱,並啟用檔案屬性加密。然後此範例會在工作表 Sheet1 中顯示 PasswordEncryptionProvider、PasswordEncryptionAlgorithm、PasswordEncryptionKeyLength 和 PasswordEncryptionFileProperties 屬性的值。此範例假設在其他地方定義 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"].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 =
this.PasswordEncryptionProvider;
Globals.Sheet1.Range["B2"].Value2 =
this.PasswordEncryptionAlgorithm;
Globals.Sheet1.Range["B3"].Value2 =
this.PasswordEncryptionKeyLength;
Globals.Sheet1.Range["B4"].Value2 =
this.PasswordEncryptionFileProperties;
Globals.Sheet1.Range["B1", "B4"].Columns.AutoFit();
}
.NET Framework 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。