vc调用excel的问题,请各位朋友捧场!

nana11 2002-03-28 04:03:27
IDispatch *pIDispatch;
pIDispatch = wssMysheets.GetItem(_variant_t("sheet1")) -->这里是sheet1
以上调用没有错误。
当把sheet1改成sheet5(一个不存在的)之后,
pIDispatch = wssMysheets.GetItem(_variant_t("sheet5")) -->这里是sheet5
却弹出一个不明对话框,里面没有任何内容。

我要问的是,通过对pIDispatch的操作而不是对sheet1/sheet5的判断,怎样确认pIDispatch的正确性?

在线等待
...全文
102 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
strangecat 2002-03-28
  • 打赏
  • 举报
回复
are you sure?
_com_error is VC COM Compiler support. It is sent with _com_issue_error.

In MSDN there is the following advise: Becuase of the reference count problem with compiler support, it is encouraged to use MFC but not "#import" to write Offiec Automation with Visual C++.

There are some exceptions defined for CDispatchDriver. Something like CDispatchException ... you can find the definition in MSDN.
chdan 2002-03-28
  • 打赏
  • 举报
回复
try{
pIDispatch = wssMysheets.GetItem(_variant_t("sheet5"));
}
catch(_com_error e)
{
CString strErr = (LPCTSTR)e.Description();
AfxMessageBox(strErr,MB_OK);
}
catch(...)
{
AfxMessageBox("未知错误!",MB_OK);
}
nana11 2002-03-28
  • 打赏
  • 举报
回复
try{
pIDispatch = wssMysheets.GetItem(_variant_t("sheet5"));
}
catch(_com_error e)
{
CString str;
str.Format("%l",e.Error);
MessageBox(str,"kfdjfdflkkjl",MB_OK);
}
这样做可以么?如果可以的话,还是收不到信息。
跟debug之后,发现在它调用的一个方法里面的一个函数除了错,而且这个错误她没有处理。
nana11 2002-03-28
  • 打赏
  • 举报
回复
试一试
chdan 2002-03-28
  • 打赏
  • 举报
回复
通过
try{

}
catch(_com_error e)
{
...
}
不能看到错误信息吗?

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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