哪位大虾帮小弟解释一下vc写excel代码阿
哪位大虾帮小弟解释一下如下代码阿
这CreateDispatch
AttachDispatch
等等这些都是干什么的阿
怎么用阿
小弟第一次用vc写excel
赐教阿
_Application excelApp;
excelApp.CreateDispatch("Excel.Application");
if(excelApp.m_lpDispatch==NULL)
{
MessageBox("Error create excel application");
return;
}
Workbooks wbs;
wbs.AttachDispatch(excelApp.GetWorkbooks());
_Workbook tempWb,DayWb;
VARIANT Template;
Template.vt=VT_I2;
Template.iVal=-4167;
DayWb.AttachDispatch(wbs.Add(Template));
Worksheets wss;
wss.AttachDispatch(DayWb.GetWorksheets());
VARIANT before,after,count,type;
after.vt=VT_DISPATCH;
COleVariant index(1L);
after.pdispVal=wss.GetItem(index);
count.vt=VT_I2;
count.iVal=1;
LPDISPATCH pws1,pws2;
pws1=wss.Add(before,after,count,type);
after.pdispVal->Release();
index.lVal=2L;
after.pdispVal=wss.GetItem(index);
pws2=wss.Add(before,after,count,type);
after.pdispVal->Release();