Programming Excel with C++ .Net (MFC)

G

Guest

Hi
I have a couple of queries about adding excel functionality to my program.
I want to open excel using a excel template or excel file that I have
already created.
I've tried using CWorkbooks::Open() method, but I new to this and am
struggling with all the VARIANT parameters.
Does anyone know how to do this or able to point me in the right direction?
Secondly, I want to be able to select a cell at run time to place some data.
I have me able to pick a row in column A using:
int Row;
CString CellStr;
..
..
..
CellStr.Format("A%d",row);
oRange = oSheet.get_Range(COleVariant(CellStr),covOptional);

Is there a better way to pick just one cell, instead of using the Range
method?
Also, is there an easy way to pick the column at runtime?

Thanks
H.
 
F

Fredrik Wahlgren

H. said:
Hi
I have a couple of queries about adding excel functionality to my program.
I want to open excel using a excel template or excel file that I have
already created.
I've tried using CWorkbooks::Open() method, but I new to this and am
struggling with all the VARIANT parameters.
Does anyone know how to do this or able to point me in the right direction?
Secondly, I want to be able to select a cell at run time to place some data.
I have me able to pick a row in column A using:
int Row;
CString CellStr;
.
.
.
CellStr.Format("A%d",row);
oRange = oSheet.get_Range(COleVariant(CellStr),covOptional);

Is there a better way to pick just one cell, instead of using the Range
method?
Also, is there an easy way to pick the column at runtime?

Thanks
H.


First of all, you should create a VBA macro that does something similar to
what you want to do from your C++ program. Once you have something that
works, it should be easier to convert to C++, especailly if you use early
binding. Here's a tool that may be useful, it converts VBA code to C++ using
late binding.

http://support.microsoft.com/kb/216388

/Fredrik
 
G

Guest

Cheers Fredrik.
I tried the translation program and can make no sense of the code it's
producing.
However I did make me think about manually translating VBA to C++, since the
classes are similiar and there is some help for them in VBA.
I have just realise that I can use covOptional for optional variants and
have been able use CWorkbooks::Open() method to open my file.
Thanks for pointing me in the right direction.

Hamish
 
F

Fredrik Wahlgren

H. said:
Cheers Fredrik.
I tried the translation program and can make no sense of the code it's
producing.
However I did make me think about manually translating VBA to C++, since the
classes are similiar and there is some help for them in VBA.
I have just realise that I can use covOptional for optional variants and
have been able use CWorkbooks::Open() method to open my file.
Thanks for pointing me in the right direction.

Hamish
AWell, with late binding, the code isn't easy to understand. The absoultely
easiest way to auomate Excel, using compiled code, is to use VB6. You simplu
pass Excel.Application to a property and then write code which will be very
similar to VBA. If you use C++, you should #imprt excel.exe (Excel 2003) so
that you can use early binding.

/Fredrik
 
P

pearl1959

I don't know if this tool could help with this...but if you want check
out www.kdcalc.com...This lets you develop your code in Excel and then
KDCalc will convert the excel spreadsheet into either a java or .Net
implementation for execution not using Excel. May not help with this
but may be useful in the future. There's a free/no registration
download of the tool to test with. I've used it a bit and it's saved me
a lot of time reprogramming.
 
P

pearl1959

I don't know if this tool could help with this...but if you want check
out www.kdcalc.com...This lets you develop your code in Excel and then
KDCalc will convert the excel spreadsheet into either a java or .Net
implementation for execution not using Excel. May not help with this
but may be useful in the future. There's a free/no registration
download of the tool to test with. I've used it a bit and it's saved me
a lot of time reprogramming.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top