少し調べてみました。 MSDNのサンプルを必要な部分だけ切り取れば こんな感じです。
これを参考にすれば解決するのではないでしょうか。
サンプルコード
_Application app; // app is an _Application object. Workbooks books; LPDISPATCH lpDisp; // Often reused variable.
// Common OLE variants. Easy variants to use for calling arguments. COleVariant covTrue((short)TRUE), covFalse((short)FALSE), covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
// Start Microsoft Excel, get _Application object, // and attach to app object. if(!app.CreateDispatch("Excel.Application")) { AfxMessageBox("Couldn't CreateDispatch() for Excel"); return; }
// Set visible. app.SetVisible(TRUE);
// Get the Workbooks collection. lpDisp = app.GetWorkbooks(); // Get an IDispatch pointer. ASSERT(lpDisp); books.AttachDispatch(lpDisp); // Attach the IDispatch pointer // to the books object. lpDisp = books.Open("C:\\sample.xls", // Test.xls is a workbook. covOptional, covOptional, covOptional, covOptional, covOptional, covOptional, covOptional, covOptional, covOptional, covOptional, covOptional, covOptional ); // Return Workbook's IDispatch pointer.
|