C++、OLE、Excel 自动化:EAccessviolation 位于 00000800

发布于 2024-07-16 03:32:38 字数 679 浏览 10 评论 0原文

我正在编写一个后台服务应用程序,它必须自动从 Excel 2003 文件读取数据。 但无论我尝试什么,方法 OlePropertyGet() 在尝试从地址“00000800”读取时总是会导致 EAccessViolation 错误。

该错误总是发生在该代码片段的最后一行,并且似乎与该方法接收的参数无关:

Variant excel, workbooks;

try
{
    excel = GetActiveOleObject("Excel.Application");
}
catch(...)
{
    excel = CreateOleObject("Excel.Application");
}

workbooks = excel.OlePropertyGet("Workbooks");

我对此进行了一些广泛的谷歌搜索,但没有发现任何有帮助的东西,只有 this 论坛帖子,有人有同样的问题,但没有给出任何信息有关原因或解决方案的信息(有点有趣的是,作者一度提到他知道原因,但没有说它是什么!)。

我愿意接受任何有关导致此问题的原因以及如何解决此问题的想法,但也欢迎 Excel OLE 自动化的替代方法。

I am writing an background service application that has to automatically read data from Excel 2003 files. But no matter what I try, the method OlePropertyGet() always results in an EAccessViolation error while trying to read from address "00000800".

The error always occurs at the last line of this code snippet, and seems independent of what parameter the method receives:

Variant excel, workbooks;

try
{
    excel = GetActiveOleObject("Excel.Application");
}
catch(...)
{
    excel = CreateOleObject("Excel.Application");
}

workbooks = excel.OlePropertyGet("Workbooks");

I've done some extensive google search on this, but found nothing that's even remotely helpful, only this forum thread where someone has the same issue, but doesn't give any information about the cause or solution (it's somewhat funny that at one point the author mentions he knows the cause, but doesn't say what it is!).

I'm open to any ideas as to what is causing this and how to solve this problem, but also alternative approaches to Excel OLE automation.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

何止钟意 2024-07-23 03:32:38

我的猜测是它的空指针问题。

看起来 GetActiveOleObject()CreateOleObject() 都不起作用。

在调用 OlePropertyGet 之前尝试检查“excel”的有效性。

我想你应该确保你已经安装了 Excel。

My guess is its a null pointer issue..

It looks like neither GetActiveOleObject() nor CreateOleObject() worked.

Try checkign the validity of 'excel' before calling OlePropertyGet.

And I guess you should make sure you have Excel installed.

如若梦似彩虹 2024-07-23 03:32:38

您可以使用 Visual Studio Tools for Office(请参阅 http://msdn.microsoft. com/en-us/library/d2tx7z6d.aspx)。

或者您可以使用 ATL 支持来实例化 Office 提供的对象模型。

You can use Visual Studio Tools for Office (see http://msdn.microsoft.com/en-us/library/d2tx7z6d.aspx).

Or you can use ATL support to instantiate the object model provided by office.

久光 2024-07-23 03:32:38

您的代码可能无法成功解析“Excel.Application”,从而导致空指针。 它使用该字符串的注册表查找来识别 Excel。 听起来您缺少该注册表项。

Your code may not be able to resolve "Excel.Application" successfully, leading to a null pointer. It uses a registry lookup with that string to identify Excel. It sounds like you're missing that registry entry.

万水千山粽是情ミ 2024-07-23 03:32:38

我使用这样的代码来确定创建的对象的有效性(在 C++ Builder 中):

Varaint excel = GetActiveOleObject("Excel.Application");
TAutoDriver<IDispatch> dispatcher;
dispatcher.Bind(excel, false);

if (dispatcher.IsBound())
{
    Variant workbooks = excel.OlePropertyGet("Workbooks");   
}

I use such code to determine validity of created objects(in C++ Builder):

Varaint excel = GetActiveOleObject("Excel.Application");
TAutoDriver<IDispatch> dispatcher;
dispatcher.Bind(excel, false);

if (dispatcher.IsBound())
{
    Variant workbooks = excel.OlePropertyGet("Workbooks");   
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文