Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Unable to open .xlsx file with password in C#

I have been working on a project where I need to open an excel document to do things. I finally got it working, but for some reason it no longer works. The code is straight forward, it is just always saying the password is wrong. It was working earlier and I can't figure out why it's not anymore.The password and file path have been verified many times that they are correct. Any help would be greatly appreciated.

static void Main(string[] args) {
        Console.WriteLine("File Path: ");
        string path = Console.ReadLine();

        Console.WriteLine("Password: ");
        string attempt = Console.ReadLine();

        var WFile = new Excel.Application();

        try {
            Excel.Workbook Wbook = WFile.Workbooks.Open(path, ReadOnly: true, Password: attempt);
            Console.WriteLine("> File Opened");
        } catch {
            Console.WriteLine("> NOT THE PASSWORD");
        }

        Console.ReadLine();           
}

Comments