Writing data to an open Excel file using COM OLE C ++

Good evening,

Can you please help me, if anyone has a sample Excel file for reading and writing data using COM / OLE in pure C ++?

There is an example of microsoft:
support.microsoft.com/en-us/help/216686/how-to-automate-excel-from-c-without-using-mfc-or-import

This example creates a new excel file and writes data to it, but how to write the data to the Open excel file, how to catch this excel file, there is no such example, and for me at the moment to modify Unfortunately, absolutely not possible, too difficult: (

Maybe someone did something like that.
you should not try to write to an open file. this can corrupt the data and lose the whole file. I have no idea how one catches a file apart from throwing their hard disk at someone... this did not translate well or something?

Writing the excel format is a pain even if you use the tools MS gives us; doing it without those is even harder. Is there any chance a CSV file will do?

Unfortunately, I have to write it to an open file, but this does not damage the data in it. CSV file is not suitable.
The only way you're going to write to an open file is to do it within excel itself.

Create a simple VBA function / macro to call out to your C++ DLL.
https://stackoverflow.com/questions/19214209/calling-c-function-from-excel-and-vba-using-dll-created-in-c

It is not true.

Can replace:

IDispatch *pXlApp;
hr = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER, IID_IDispatch, (void **)&pXlApp);
if(FAILED(hr)) {
::MessageBox(NULL, "Excel not registered properly", "Error", 0x10010);
return -2;
}

On:

IUnknown* pUnk;
hr = GetActiveObject(clsid, NULL, &pUnk);
if (FAILED(hr)) {
::MessageBoxA(NULL, "GetActiveObject failed!", "Error", 0x10010);
return -2;
}


My only question now is how to write down the string, not just the number, in Excel.


Topic archived. No new replies allowed.