If someone knows how to go from Excel::Window pointer to real value in opened Excel cell, please let me know.
Here is the task conditions:
– Excel is currently running in one single window with one workbook on one sheet
– some cells have data (to simplify let’s say only one cell[1,1] has data, which is “a”)
The question is how to find out that only one cell has data, and cell is [1,1] and the data is “a”.
To start with here is a code snippet:
int main( int argc, CHAR* argv[])
{
CoInitialize( NULL );
HWND excelWindow = FindWindow(L"XLMAIN", NULL);
EnumChildWindows(excelWindow, (WNDENUMPROC) EnumChildProc, (LPARAM)1);
return 0;
}
BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM)
{
WCHAR szClassName[64];
if(GetClassNameW(hwnd, szClassName, 64))
{
if(_wcsicmp(szClassName, L"EXCEL7") == 0)
{
Excel::Window* pWindow = NULL;
HRESULT hr = AccessibleObjectFromWindow(hwnd, OBJID_NATIVEOM, __uuidof(Excel::Window), (void**)&pWindow);
if(hr == S_OK)
{
// Here we need to answer the question using pWindow
pWindow->Release();
}
return false;
}
}
return true;
}
Here is code finally used:
The AutoWrap() function has been taken from http://support.microsoft.com/kb/216686/en-us?fr=1, while the initial sample from http://www.northatlantawebdesign.com/index.php/2009/07/15/access-microsoft-excel-2007-com-api-through-microsoft-active-accessibility/
Thanks to all who helped.