VC 插入excel
CString ePath,iPath; m_ePath.GetWindowText(ePath); m_iPath.GetWindowText(iPath); _Application app; Workbooks books; _Workbook book; Worksheets sheets; _Worksheet sheet; Shapes shp; //创建Excel 2000服务器(启动Excel) if (!app.CreateDispatch("Excel.Application",NULL)) { AfxMessageBox("创建Excel服务失败!"); exit(1); } books.AttachDispatch(app.GetWorkbooks()); book.AttachDispatch(books.Add(_variant_t(ePath))); //得到Worksheets sheets.AttachDispatch(book.GetWorksheets()); sheet.AttachDispatch(sheets.GetItem(_variant_t("Sheet1"))); shp.AttachDispatch(sheet.GetShapes()); shp.AddPicture(iPath,false,true,0,0,400,300); app.SetVisible(true); book.PrintPreview(_variant_t( false ));//打印预览 //释放对象 sheet.ReleaseDispatch(); sheets.ReleaseDispatch(); book.ReleaseDispatch(); books.ReleaseDispatch(); app.ReleaseDispatch();