在c++或c#中打开密码保护Excel文件,提示输入密码,即使我传递了密码参数

时间:2021-07-05 06:25:48

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.

我使用Microsoft.Office.Interop。Excel在我的c++ /CLI程序中打开一个密码保护的Excel文件。我提供一个密码作为第五个参数。当我运行我的程序时,Excel启动并打开我的文件,但它提示输入密码。注意,该文件是密码保护的,而不是工作表。

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 个解决方案

#1


1  

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

将readonly参数(第3个)更改为true实际上可以起到作用(除了在readonly中打开):

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

#1


1  

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

将readonly参数(第3个)更改为true实际上可以起到作用(除了在readonly中打开):

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