C++、OLE、Excel 自动化:EAccessviolation 位于 00000800
我正在编写一个后台服务应用程序,它必须自动从 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我的猜测是它的空指针问题。
看起来
GetActiveOleObject()
和CreateOleObject()
都不起作用。在调用
OlePropertyGet
之前尝试检查“excel”的有效性。我想你应该确保你已经安装了 Excel。
My guess is its a null pointer issue..
It looks like neither
GetActiveOleObject()
norCreateOleObject()
worked.Try checkign the validity of 'excel' before calling
OlePropertyGet
.And I guess you should make sure you have Excel installed.
您可以使用 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.
您的代码可能无法成功解析“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.
我使用这样的代码来确定创建的对象的有效性(在 C++ Builder 中):
I use such code to determine validity of created objects(in C++ Builder):