[C#] Excel、Word 解鎖

  • 622
  • 0

沒事不要亂改成暴力破解法唷~
小心使用

Word比照辦理,流程一樣
連參數的位置都一樣!

using Excel = Microsoft.Office.Interop.Excel;

class Program
{
    static void 斷開鎖鍊(string Path)
    {
        Excel.Application xlApp = new Excel.Application()
        {
            DisplayAlerts = false //關閉警告
        };

        List<string> PasswordList = db.密碼清單.select(x=>x.密碼).ToList();
 
        foreach (string pw in PasswordList)
        {
            try
            {
                object ReadOnly = true;
                object missing = System.Reflection.Missing.Value;
                xlWorkbook = xlApp.Workbooks.Open(Path, missing, ReadOnly, missing, pw);
                
                是否開啟成功 = true;
                Password = pw;
                //PasswordList.Remove(pw); //看需要,筆對到的list移除可減少迴圈次數
                break;
            }
            catch
            {
                是否開啟成功 = false;
            }
        }
    }
}