OLE控制Excel的问题 (OlePropertySet异常)

SeekTruth 2003-08-19 04:55:12
开发环境:
WinXP Pro版
C++Builder 6.0企业版

在使用OLE提取Excel文件数据时,发生访问违例异常!
  程序代码如下:
TOpenDialog * dlg=new TOpenDialog(this);
dlg->Filter="Excel文件(.xls)|*.xls";
if(dlg->Execute())
{
Variant Ex,Wk,Sheet,Sh1;
Ex=Variant::CreateObject("Excel.Application");
____________________________________
Ex.OlePropertySet("Visible",false);
_______________________________________
Ex.OlePropertyGet("WorkBooks").OleProcedure("Open",dlg->FileName.c_str(),false,0);
Wk=Ex.OlePropertyGet("ActiveWorkBook");
Sheet=Wk.OlePropertyGet("Sheets");

int nCount=Sheet.OlePropertyGet("Count");
ShowMessage(nCount);
for(int i=0;i<nCount;i++)
{
Sheet.OlePropertyGet("Item",i+1).OleProcedure("Select");
ShowMessage(Wk.OlePropertyGet("ActiveSheet").OlePropertyGet("Name"));
}

Ex.OleFunction("Quit");
}

问题:

   
以上代码在一个新建的工程中能够正常运行,然将其移值至一MDI工程中时
---------------------------------------
  程序运行至
Ex.OlePropertySet("Visible",false);
即发生访问违例异常(AV)

  哪位大虾碰到过这种情况的,请指教?


...全文
117 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
SeekTruth 2003-08-21
  • 打赏
  • 举报
回复


谢谢7rainbow(jiejie)的回贴.

SeekTruth 2003-08-20
  • 打赏
  • 举报
回复


老规矩,自己UP。
SeekTruth 2003-08-19
  • 打赏
  • 举报
回复

 已经加了啊。
7rainbow 2003-08-19
  • 打赏
  • 举报
回复
你在前面加上CoIntiailize();
试试。

13,822

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧