求助,MFC操作EXCEL时,导出的类CWorksheet的Add方法的四项参数如何填写,导出的函数定义如下:
LPDISPATCH Add(VARIANT& Before, VARIANT& After, VARIANT& Count, VARIANT& Type)
{
LPDISPATCH result;
static BYTE parms[] = VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT ;
InvokeHelper(0xb5, DISPATCH_METHOD, VT_DISPATCH, (void*)&result, parms, &Before, &After, &Count, &Type);
return result;
}
如果我把四项参数都填成缺省值,没问题,可以通过:
......
#define eOptional COleVariant((long)DISP_E_PARAMNOTFOUND, VT_ERROR)
......
CExcelWorksheets WorkSheets = m_App.get_Worksheets();
CExcelWorksheet WorkSheet = WorkSheets.get_Item(COleVariant(WorkSheets.get_Count()));
WorkSheets.Add(eOptional,eOptional,eOptional,eOptional);
此时由于Before和After参数都是缺省值,新添加的Sheet将会在所有Sheet之前,如果我想让新添加的Sheet在所有Sheet之后,那必须要填After参数,问题是现在不知道该如果填这个参数,填COleVariant((long)WorkSheets.get_Count())的话报错:类Sheet的Add方法无效
求大神帮助
mfc excel
------解决方案--------------------------------------------------------
_Worksheet wsa ;
wsa.AttachDispatch(m_wsSheets.GetItem(COleVariant(m_wsSheets.GetCount())));
m_wsSheets.Add(vtMissing,_variant_t(wsa),vtMissing,vtMissing);