automating Excel in C++

A

alexander chupeev

I can use the following statement in Visual Basic.NET application to refer a
row in Excel spreadsheet:

Imports Excel = Microsoft.Office.Interop.Excel
....
Dim wst as Excel.Worksheet = app.ActiveSheet
wst.Rows(2).Locked = True

I need your help to automate Excel the same way with Visual C++. The Rows
property of Excel::Worksheet object cannot be used in array context in C++,
so I suppose that the following piece of code will be equvalent to previous
one:

#import "C:\Program Files\Microsoft Office\Office11\Excel.exe" \
auto_search auto_rename dual_interfaces exclude("IFont", "IPicture")
....
Excel::_WorksheetPtr wst = app->ActiveSheet;
wst->Rows->_Range[2L][vtMissing].Locked = VARIANT_TRUE;
^?????

The last line always throw a runtime exception
 
A

Alvin Bruney [MVP]

another alternative is to just use the Office Web Components which has an
excel object that is fully functional

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ http://www.lulu.com/owc
----------------------------------------------------------


Mark Jerde said:
Off topic, but I ran across this alternative
http://www.excelgenerator.com/
in this thread.
http://discuss.joelonsoftware.com/default.asp?joel.3.66572.10

I'm going to try it the next time I need to work with Excel.

-- Mark

alexander said:
I can use the following statement in Visual Basic.NET application to
refer a row in Excel spreadsheet:

Imports Excel = Microsoft.Office.Interop.Excel
...
Dim wst as Excel.Worksheet = app.ActiveSheet
wst.Rows(2).Locked = True

I need your help to automate Excel the same way with Visual C++. The
Rows property of Excel::Worksheet object cannot be used in array
context in C++, so I suppose that the following piece of code will be
equvalent to previous one:

#import "C:\Program Files\Microsoft Office\Office11\Excel.exe" \
auto_search auto_rename dual_interfaces exclude("IFont", "IPicture")
...
Excel::_WorksheetPtr wst = app->ActiveSheet;
wst->Rows->_Range[2L][vtMissing].Locked = VARIANT_TRUE;
^?????

The last line always throw a runtime exception
 

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