打开密码保护的Excel文件在C + +或C#提示输入密码,即使我已经传递了一个参数的密码 [英] Opening password protected Excel file in C++ or C# prompts for password even though I've passed an argument for password

查看:1038
本文介绍了打开密码保护的Excel文件在C + +或C#提示输入密码,即使我已经传递了一个参数的密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

根据文档,密码应该是类型对象,但提供它作为文字也应该工作? p>

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);


推荐答案

将只读参数(除了它以只读方式打开):

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

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

这篇关于打开密码保护的Excel文件在C + +或C#提示输入密码,即使我已经传递了一个参数的密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆