GAers:
I?m trying to use VC to open Excel and manipulate a worksheet. I?m
importing Excel9.OLB, which can be located in C:\Program
Files\Microsoft Office\Office\ -- assuming the default installation
folder. Depending on your version of Excel, the OLB filename might be
slightly different... ExcelXX.OLB. I encourage you to look at it
using OLE/COM Object Viewer.
I can successfully instantiate an instance of _Application using
CoCreateInstance(). From there, I can get Workbooks, _Workbook,
Sheets, and _Worksheet. However, the problem occurs when I try to
call the _Worksheet method called get_Range(). It?s defined as
follows...
_Worksheet::get_Range(VARIANT Cell1, VARIANT Cell2, RANGE **RHS).
I make my call this way...
// sheet is declared/initialize prior
Range *range = NULL;
sheet->get_Range(_variant_t(?A1?), _variant_t(?A2?), &range);
After I have the range, I need to call the method Activate(VARIANT
*RHS). However, I cannot call methods to that variable unless I use
Invoke(), DISPPARAMS, etc, which makes my code very bloated. How can
I create an object of type IRange, which is the interface to make easy
method calls?
I?ve tried various ways?
// sheet is obtained before hand
IRange *range = NULL;
IDispatch *temp = NULL;
sheet->get_Range(_variant_t(?A1?), _variant_t(?A2?), (Range **)&temp);
temp->QueryInterface(__uuidof(Range), (void **)&range);
VARIANT var; // var is just a return message indicating success or failure
VariantInit(&var);
range->Activate(&var);
This attempt does not work. Again, any suggestions on how I can
create an object of type IRange, so I can easily call methods would be
much appreciated as calling Invoke() from the data type Range is
encumbering my code.
I thank you all for those who try to assist me in my endeavor. Also,
I hope others find your solutions helpful if they -- too -- have the
same or similar problems. Thank you once again. |