Re[2]: MFCからExcelの操作


[コメントツリー表示を見る] [発言時刻順表示を見る]

Posted by Uz on 2000/09/11 07:07:05

In Reply to: Re: MFCからExcelの操作 Posted by Uz on 2000/09/11 06:34:00


    少し調べてみました。
    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.


記事スレッド一覧