打开密码保护的Excel工作簿C#

时间:2014-05-30 05:02:33

标签: c# excel com-interop password-protection

我正在尝试打开受密码保护的Excel工作簿。我尝试了许多不同的方法来以编程方式取消保护或输入密码,但每次我的程序运行时,我都会提示输入密码。我做错了什么?

 public class AttenFile
    {
        private Excel.Application excel;
        private Excel.Workbook wb;
        private Excel.Worksheet worksheet;
        private Excel.Range range;
        private const  int startRow = 3;
        private int row;
        private static Object MissingValue = System.Reflection.Missing.Value;

        public AttenFile(String attenFileDir)
        {
            excel = new Excel.Application();
            wb = excel.Workbooks.Open(attenFileDir, MissingValue, MissingValue, MissingValue, "nso" );
            wb.Unprotect("nso");
            worksheet = (Excel.Worksheet) wb.Sheets[1];
            worksheet.Unprotect("nso");
            range = worksheet.UsedRange;
        }
}

0 个答案:

没有答案