Excel Automation: how to get ranges like "A1:D1"

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
testalucida
Knows some wx things
Knows some wx things
Posts: 35
Joined: Mon Jan 15, 2007 8:10 pm

Excel Automation: how to get ranges like "A1:D1"

Post by testalucida » Thu May 01, 2008 12:44 pm

Hi all,

I'm just playing with automating excel and can't find a way how to get ranges of more than 1 cell.

Following code works pretty:

Code: Select all

wxAutomationObject rng;
wxVariant cellRange[] = {wxVariant(wxT("A1:D1"))};
bool rc = m_activeSheet.GetObject( rng, wxT( "Range" ), 1, cellRange );
rc == 0, but how can I read the 4 values contained in rng?

I tried

Code: Select all

wxVariant value = rng.GetProperty( wxT( "Value"), cellRange[0] );
and

Code: Select all

wxVariant value = rng.GetProperty( wxT( "Value") );
but value data always was NULL.

Any help appreciated!

Thanks in advance
testalucida

timg
Earned some good credits
Earned some good credits
Posts: 148
Joined: Mon Jan 23, 2006 6:52 pm

Post by timg » Thu May 01, 2008 9:39 pm

I haven't tried to copy data out of Excel before like this, but I don't think it would work the way you are doing it.

You might want to try making your wxVariant an array at least as big as what you are trying to get.

testalucida
Knows some wx things
Knows some wx things
Posts: 35
Joined: Mon Jan 15, 2007 8:10 pm

Post by testalucida » Sat May 03, 2008 3:09 pm

Hi timg,

I can't imagine why it should be me to allocate this array. In my opinion it's COM to do that for me.

OLE in wx seems to be an obscure and rarely used API, so probably I'll do my job with ATL. That is in fact nasty but better documented than the wx-approach and you'll find lots of examples in the www.

Thx to you and bye
testalucida

Post Reply