C++ 创建 excel 文档

问题描述 投票:0回答:0

我正在尝试从 C++ 创建一个 excel 文件。

当我尝试这个时,我得到 CLSID_Application 未定义:

#include <iostream>
#include <cstring>
#include <windows.h>
#include <ole2.h>
#include <OCIdl.h>
#include <OleCtl.h>
#include <atlbase.h>
#include <atlcom.h>
#include <Windows.h>


using namespace std;



int main() {
    HRESULT hr;

    // Initalize COM Library
    hr = CoInitialize(NULL);
    if (FAILED(hr))
    {
        cout << "Failed to Initialize COM Library" << endl;
        return 1;
    }

    // Create instance of Excel application
    IDispatch* pExcel = NULL;
    hr = CoCreateInstance(CLSID_Application, NULL, CLSCTX_LOCAL_SERVER, IID_IDispatch, (void**)&pExcel);
    if (FAILED(hr))
    {
        // Handle the error
    }
c++ winapi com
© www.soinside.com 2019 - 2024. All rights reserved.