|
I want to get the already open excel sheet and get the cell value using IDispatch. Trioum
|
|
|
|
|
|
CoInitialize(NULL);
HRESULT hr;
CLSID clsidExcelApp;
hr = CLSIDFromProgID(L"Excel.Application", &clsidExcelApp);
IUnknown *pUnk = 0;
hr = GetActiveObject(clsidExcelApp, NULL, &pUnk);
if(SUCCEEDED(hr))
{
IDispatch *pDisp = 0;
hr = pUnk->QueryInterface(IID_IDispatch, (void**)&pDisp);
CApplication oApp(pDisp);
CWorkbooks oBooks = oApp.get_Workbooks();
CWorkbook oBook = oBooks.get_Item(COleVariant((short)1));
CWorksheets oSheets = oBook.get_Worksheets();
CWorksheet oSheet = oSheets.get_Item(COleVariant((short)1));
oSheet.Activate();
CRange oRange = oSheet.get_Range(COleVariant(CString(L"A1")), COleVariant(CString(L"A1")));
COleVariant var = oRange.get_Text();
MessageBox(var.bstrVal, L"Text in cell A1");
}
|
|
|
|
|
I good I get it . But I am facing two problems
(a) : I am not able to get the cell change event . i.e. as the value in cell change My application get the event that which is cell i.e. its row and col .
(b) as I click on any cell in edit mode application hang .
Trioum
|
|
|
|
|
Get IConnectionPointContainer interface of the application object, and get connection point to the events you want to catch. In this case, i think you have to deal with WorkBookEvents and DocEvents. Several documentations are available..
catching events from word
handling events for excel
create sink event for COM client
Use OLE-COM object viewer to get exact UUID of the events you want to trap.
best of luck.
|
|
|
|
|
I got the event of sheet change but still not getting the value of cell and its location i.e. row and col of cell in the function .
STDMETHODIMP CAppEventListener::HandleSheetChange( IDispatch* xlSheet,
IDispatch* xlRange)
{
OutputDebugString("HandleSheetChange\n");
HRESULT hr = S_OK;
return hr;
}
Trioum
|
|
|
|
|
did u examine the xlRange value? I think it will contain the cell range where the event is fired. Try calling get_Text() on this range to get text in the cell.. see various methods on Range object..

|
|
|
|
|
but i am not getting the get_text() method . in this function .
Trioum
|
|
|
|
|
how did u try it? please show a bit of code..
|
|
|
|
|
STDMETHODIMP CAppEventListener::HandleSheetChange( IDispatch* xlSheet,
IDispatch* xlRange)
{
OutputDebugString("HandleSheetChange\n");
xlRange-> here not gettting text method
HRESULT hr = S_OK;
return hr;
}
Trioum
|
|
|
|
|
oh.. You did exactly as i guessed . xlRange is Range object's IDispatch iterface. If you haven't already done, add a Range class (say CRange) to the project from EXCEL.exe using 'Add MFC Class from Typelib' wizard. Then
CRange oRange(xlRange);
See the methods on Range object now by using oRange. ---- 
|
|
|
|
|
Done it . but exe is crashing as I call getText()
Trioum
|
|
|
|
|
Now by lot of R&D problem is solved . Can you guide me for SheetCalculate event . its example is not given on the site.
Trioum
|
|
|
|
|
well done OLE automation may need some R&D most time.
You can catch SheetCalculate event in much the same way you did for SheetChange event. Mean, all reside in IAppEvent interface, so Advice() for it, and override the SheetCaluclate method.
<br />
HRESULT _stdcall SheetCalculate(IDispatch* pSheetDisp)<br />
{<br />
CWorkSheet oSheet(pSeetDisp);<br />
}<br />
|
|
|
|
|
I got it and do it , but facing one more problem as in case on "change event" I got the cell number i.e its row and column in which value is change . But "calculate event" fire when there is reference of another cell or cell containing formulae and when value change in such cell in this case I am not getting the cell no i.e cell row and column . this is my problem it become very tedious when I have the thousand of such cells having reference of various cells and formulaes. In this case I have to parse every cell to find out the value change . this become very slow for my project .I am searching the way to find out the cell row and column when there is calculate event fire .
Trioum
|
|
|
|
|
Now I am facing one more problem . I have multiple excel file runnig on one system , but I am getting only one excel file using GetActiveObject. when I close this then I am getting second one using get object . so why I am not getting all the excel files ??
Trioum
|
|
|
|
|
Hello, I'm trying to add text-to-speech support to my emulator, this was simple to do on the Amiga version but is causing lots of headaches under Windows.
I'm linking with the sapi.lib from the official Speech SDK 5.1, everything is compiling fine but I'm getting these linker errors:
ibm1.obj : error LNK2001: unresolved external symbol _IID_IVTxtNotifySinkA
ibm1.obj : error LNK2001: unresolved external symbol _CLSID_VTxt
ibm1.obj : error LNK2001: unresolved external symbol _IID_IVoiceTextA
Aren't these supposed to be defined in sapi.lib? So why am I still getting linker errors? I'm using Visual C 5.0 and WinXP SP2. Thanks.
|
|
|
|
|
|
Hello,
How to iterate (infact access) the vtable of COM coclass(that will implement the methods of its exposed interfaces).?
Only I need to access vtable where all addresses of exposed methods of its interfaces are stored.
e.g Say
Math is COM object
and its exposed interface is "Operations"
and "Sum" is the method of this interface.
I need the address of "Sum"
Regards
Muhammad Usman Khalil
|
|
|
|
|
Checking the first 4 bytes of the location pointed to by the interface pointer returned by CoCreateInstance() function might give you the address of vtable (I have not tried it). But why do you want to do this?
|
|
|
|
|
I need to call all the functions of COM Interface exposed methods at runtime.
For this I need to access vtable of COM coclass where all addresses of exposed methods of its interfaces are stored.
e.g Say
Math is COM object
and its exposed interface is "Operations"
and "Sum" is the method of this interface.
I need the address of "Sum", so that I can call it on run time. Just like you use loadlibrary for DLL and adter passing functional address, using GetProcAddress we can call function at runtime.
Here in COM same I need to do. But here no LoadLibrary , and no GetProcAddress. Just we need to iterate vtable and one by one we'll get the addresses of methods and we'll call these methods on run time.
Any Suggestions?
|
|
|
|
|
Take a look at this article[^] which explains the basics of the COM vtable and pointers, it should help you understand how to get what you want. txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
|
Even if you get the function pointers this way, how to get the function signature (arguments and types)? You may have to use type library to get more details about the interface functions and supported interfaces.
|
|
|
|
|
a coclass will always have pointers to virtual tables (of all interfaces it implements) as its instance data. In CreateObject() function, coclass is instantiated, type casted to the interface ptr which we demands through CoCreaInstance and returned. so the returned ptr will be pointing to the virtual table of that interface. This virtual table ptr is used later in function calls to locate the correct implemented functions. Pls correct me if iam wrong..
|
|
|
|