在VC中如何处理嵌入的excel事件
展开全部
根据微软的技术文章,调试运行时老提示内存访问异常。已解答,网站有详细说明和重点划分。(详细访问:网页链接)仅供参考
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2018-08-14 · 百度认证:云南新华电脑职业培训学校官方账号
云南新华电脑学校
云南新华电脑学校是经云南省教育厅批准成立的省(部)级重点计算机专业学校,采用三元化管理模式,教学设备先进,师资雄厚学生毕业即就业,学院引进了电商企业入驻,创建心为电商创业园区,实现在校即创业
向TA提问
关注
展开全部
Article ID: 309301 - HOW TO: Handle Events for Excel by Using Visual C++ .NET,在VC工程中自动生成了用于接收处理excel事件的代码:
/******************************************************************************
* Invoke -- Takes a dispid and uses it to call another of this class's
* methods. Returns S_OK if the call was successful.
******************************************************************************/
STDMETHODIMP CAppEventListener::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid,
WORD wFlags, DISPPARAMS* pDispParams,
VARIANT* pVarResult, EXCEPINFO* pExcepInfo,
UINT* puArgErr)
{
switch(dispIdMember){
case 0x00622:
if(pDispParams->cArgs !=2)
return E_INVALIDARG;
else
{
if(pDispParams->rgvarg[1].vt & VT_BYREF)
{
HandleBeforeWorkbookClose( // Call the function.
*(pDispParams->rgvarg[1].ppdispVal),
pDispParams->rgvarg[0].pboolVal);
}
else
{
HandleBeforeWorkbookClose( // Call the function.
(pDispParams->rgvarg[1].pdispVal),
pDispParams->rgvarg[0].pboolVal);
}
}
case 0x0061c:
{
if(pDispParams->rgvarg[1].vt & VT_BYREF)
{
HandleSheetChange( // Call the function.
*(pDispParams->rgvarg[1].ppdispVal),
*(pDispParams->rgvarg[0].ppdispVal));
}
else
{
HandleSheetChange( // Call the function.
pDispParams->rgvarg[1].pdispVal,
pDispParams->rgvarg[0].pdispVal);
}
}
break;
}
return S_OK;
}
……
/******************************************************************************
* HandleSheetChange -- This method processes the SheetChange event for the
* application attached to this event handler.
******************************************************************************/
STDMETHODIMP CAppEventListener::HandleSheetChange( IDispatch* xlSheet,
IDispatch* xlRange)
{
OutputDebugString("HandleSheetChange\n");
COleVariant
covTrue((short)TRUE),
covFalse((short)FALSE),
covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
CApplication V_app;
CWorkbook V_book;
CWorksheet V_sheet;
CRange0 V_range;
long V_Row = 0;
long V_Column = 0;
V_sheet.AttachDispatch(xlSheet);
V_app=V_sheet.get_Application();
V_range.AttachDispatch(V_app.get_ActiveCell());
V_book=V_app.get_ActiveWorkbook();
V_Column=V_range1.get_Column();
V_Row=V_range1.get_Row();
V_range.put_Value2(COleVariant("测试成功!"));
HRESULT hr = S_OK;
return hr;
/******************************************************************************
* Invoke -- Takes a dispid and uses it to call another of this class's
* methods. Returns S_OK if the call was successful.
******************************************************************************/
STDMETHODIMP CAppEventListener::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid,
WORD wFlags, DISPPARAMS* pDispParams,
VARIANT* pVarResult, EXCEPINFO* pExcepInfo,
UINT* puArgErr)
{
switch(dispIdMember){
case 0x00622:
if(pDispParams->cArgs !=2)
return E_INVALIDARG;
else
{
if(pDispParams->rgvarg[1].vt & VT_BYREF)
{
HandleBeforeWorkbookClose( // Call the function.
*(pDispParams->rgvarg[1].ppdispVal),
pDispParams->rgvarg[0].pboolVal);
}
else
{
HandleBeforeWorkbookClose( // Call the function.
(pDispParams->rgvarg[1].pdispVal),
pDispParams->rgvarg[0].pboolVal);
}
}
case 0x0061c:
{
if(pDispParams->rgvarg[1].vt & VT_BYREF)
{
HandleSheetChange( // Call the function.
*(pDispParams->rgvarg[1].ppdispVal),
*(pDispParams->rgvarg[0].ppdispVal));
}
else
{
HandleSheetChange( // Call the function.
pDispParams->rgvarg[1].pdispVal,
pDispParams->rgvarg[0].pdispVal);
}
}
break;
}
return S_OK;
}
……
/******************************************************************************
* HandleSheetChange -- This method processes the SheetChange event for the
* application attached to this event handler.
******************************************************************************/
STDMETHODIMP CAppEventListener::HandleSheetChange( IDispatch* xlSheet,
IDispatch* xlRange)
{
OutputDebugString("HandleSheetChange\n");
COleVariant
covTrue((short)TRUE),
covFalse((short)FALSE),
covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
CApplication V_app;
CWorkbook V_book;
CWorksheet V_sheet;
CRange0 V_range;
long V_Row = 0;
long V_Column = 0;
V_sheet.AttachDispatch(xlSheet);
V_app=V_sheet.get_Application();
V_range.AttachDispatch(V_app.get_ActiveCell());
V_book=V_app.get_ActiveWorkbook();
V_Column=V_range1.get_Column();
V_Row=V_range1.get_Row();
V_range.put_Value2(COleVariant("测试成功!"));
HRESULT hr = S_OK;
return hr;
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询