Excel OLE automation using Visual C++ (Autowrap function) HOW TO READ AN EXCEL CELL?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi:
Somehow I found an example code (a Wrapper, now I understand) and Im able with this code to Open, Close, even write to a particular Excel Cell [Im using Visual C++ 2010 EXPRESS EDITION]; however so far I cannot READ from an Excel Cell.
If you are familiar with this AutoWrap (or formerly, OLEMethod) function, I would appreciate it if you could suggest a procedure to READ from a particular cell in EXCEL (all the hurdles to Open, Activate certain sheet in a file, and even WRITE to a Cell have been succesfully overcame).
Here is part of the code...
Thank you in advance. Please, just comments from people well aware of this code. Thanks again!
PS. AutoWrap function not shown (however you can notice function calls to AutoWrap...the lines below are just an example). Suppose also I have activated the worksheet needed...everything ready to READ from an Excel File...HOW COULD I INSTRUCT THE AUTOWRAP FUNCTION TO READ A CELL (Is it a
DISPATCH_PROPERTYPUT/ or GET or just a DISPATCH_METHOD the one required while calling the AutoWrap function)?
// Initialize COM for this thread...
CoInitialize(NULL);
// Get CLSID for our server...
CLSID clsid;
HRESULT hr = CLSIDFromProgID(L
"Excel.Application", &clsid);if(FAILED(hr)) {
// ::MessageBox(NULL, "CLSIDFromProgID() failed", "Error", 0x10010);

}
return -1;// Start server and get IDispatch...
hr = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER, IID_IDispatch, (
void **)&pXlAppGlobal);if(FAILED(hr)) {
// ::MessageBox(NULL, "Excel not registered properly", "Error", 0x10010);

}
VARIANT x;
x.vt = VT_I4;
x.lVal = 1;
funcionesExcel::AutoWrap(DISPATCH_PROPERTYPUT, NULL, pXlAppGlobal, L
VARIANT result;
VariantInit(&result);
funcionesExcel::AutoWrap(DISPATCH_PROPERTYGET, &result, pXlAppGlobal, L
pXlBooksGlobal = result.pdispVal;
VARIANT sFname= {0} ;
VariantInit(&sFname);
return -2;"Visible", 1, x);"Workbooks", 0);
sFname.bstrVal = SysAllocString( trayectoria_pointer );
sFname.vt = VT_BSTR;
VARIANT resultado;
VariantInit(&resultado);
funcionesExcel::AutoWrap(DISPATCH_PROPERTYGET, &resultado, pXlBooksGlobal, L
pXlBookGlobal = resultado.pdispVal;
"Open",1,sFname);


View the full article
 
Back
Top