Click here to Skip to main content
15,891,851 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a password protected Excel file and I need to read this file. To Open the file I'm using Microsoft Office Interop.Ecel dll and providing the below command. But still it is asking for the password as user prompt.



Could any one please help me in this issue.

C#
using Excel = Microsoft.Office.Interop.Excel;

Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application(); 

if (xlApp == null) 
{ 
Console.WriteLine("EXCEL could not be started. Check that your office installation and project references are correct.");

return; 
}

string Password = "myPassword"; 
string Password_Unprotect = "UnProtectNow";
xlApp.DisplayAlerts = false; 
xlApp.Visible = false; 


Excel.Workbook wbk = xlApp.Workbooks.Open(@"D:\MyWorkbook.xlsb", 0, false, 5, Password, "", false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);

wbk.Password = Password; 
wbk.Unprotect(Password_Unprotect);



Thanks & Regards,
Mathi.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900