16,548
社区成员




::CoInitialize(NULL);
CWorkbooks xlBooks;
CWorkbook xlBook;
CApplication m_ExcelApplication; //excel服务对象
CWorksheets sheets;
CWorksheet sheet;
m_AppEventListener = NULL;
if(!m_ExcelApplication.CreateDispatch("Excel.Application",NULL))
{
MessageBox(NULL,"excel创建对象错误","类COperatorExcel from dll",MB_OK|MB_ICONWARNING);
return false;
}
xlBooks.AttachDispatch(m_ExcelApplication.get_Workbooks(),true);
xlBook.AttachDispatch(xlBooks.Add(_variant_t("c://1.xls")));
//得到 worksheets
sheets.AttachDispatch(xlBook.get_Worksheets(),true);
sheet = sheets.get_Item(COleVariant((short)1));
m_ExcelApplication.put_Visible(true);
m_ExcelApplication.put_UserControl(false);
...
int nIndex = 2; //你要删除的worksheet序号 sheet2
sheet = sheets.get_Item(COleVariant((short)nindex));
sheet.Delete();