Opening password protected Excel file in C++ or C# prompts for password even though I've passed an argument for password

风格不统一 提交于 2019-12-11 11:24:16

问题


I'm using the Microsoft.Office.Interop.Excel to open an password protected Excel file from my C++/CLI program. I supply a password as the 5th argument. When I run my program, Excel starts and opens my file but it prompts for password. Note that the file is password protected, not the worksheets.

According to the documentation the password should be of type object but supplying it as a literal should also work?

    using namespace System;
    using namespace Microsoft::Office::Interop::Excel;
    Microsoft::Office::Interop::Excel::Application^ exApp= gcnew Microsoft::Office::Interop::Excel::ApplicationClass();
    String^ filename="e:\\test.xls";
    Workbook^ wb = exApp->Workbooks->Open(filename, Type::Missing, Type::Missing, Type::Missing, "passw1", Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing);

回答1:


Changing the readonly argument (3rd) to true actually does the trick (except that it opens in readonly):

exApp->Workbooks->Open(filename, Type::Missing, true, ...


来源:https://stackoverflow.com/questions/29204623/opening-password-protected-excel-file-in-c-or-c-sharp-prompts-for-password-eve

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!