以下是我的代碼。但密碼不會被刪除。當我手動打開Word時,密碼對話框仍然彈出。如何使用Interop在c中刪除Word密碼#
我也嘗試了Unprotect方法,但那也行不通。
private static void WordUnProtect(string fileName, string password)
{
var app = new Word.Application();
Word.Document doc = null;
try
{
doc = app.Documents.Open(fileName, PasswordDocument: password);
// this doesn't work also
//doc.Unprotect();
doc.Password = string.Empty;
doc.Save();
}
finally
{
if (doc != null)
{
doc.Close(false);
Marshal.ReleaseComObject(doc);
}
if (app != null)
{
app.Quit();
Marshal.ReleaseComObject(app);
}
}
}
也許嘗試相當於_save as_。這就是用戶通常以交互方式使用Word時的做法 – MickyD