using System;
using Word = Microsoft.Office.Interop.Word;
namespace RemoveWordPassword
{
class Program
{
static void Main(string[] args)
{
// 创建Word应用程序对象
Word.Application wordApp = new Word.Application();
// 隐藏Word应用程序窗口
wordApp.Visible = false;
// 要处理的文档路径
string documentPath = @"C:\path\to\your\document.docx";
// 打开有密码保护的文档
Word.Document doc = wordApp.Documents.Open(documentPath, ReadOnly: false, PasswordDocument: "yourpassword");
// 移除文档的密码
doc.Password = string.Empty;
// 保存并关闭文档
doc.SaveAs2(documentPath);
doc.Close();
// 退出Word应用程序
wordApp.Quit();
// 释放COM对象
System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApp);
wordApp = null;
Console.WriteLine("文档密码已成功移除。");
}
}
}
08-07
846
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
06-19
111
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
12-27
1836
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-22
167
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-07
2764
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-31
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交