Adding an Excel Spreadsheet to Windows form

jwebb

Member
Joined
Sep 4, 2006
Messages
11
Programming Experience
Beginner
I'd like to add a form containing an excel spreadsheet (to be used as a running log) to my application.

I can add the spreadsheet on the form as an active x type. I can relocate, resize with no issues. I cannot manipulate the cells programatically as I can an Excel worksheet running in its own application.

'Invalid Active X State' Exception keeps popping up.

I'm at a loss, your help would be appreciated.

Jason
 
see post 4 in this thread for an ActiveX component that can be used to display and edit Office documents in a form.
 
Is there any way to look at this sample code without installing C++ which is t he native language of that article.

I had, in fact, looked at this earlier only to realize that fact. Can you give me some insight on the mechanics?
 
No, it's old Visual Basic code prior to .Net, using it with VB.Net is just about identical. (it's the component that is written with c++, but it is an ActiveX object so it doesn't matter with what language the component was written internally)
 
John H...I appreciate the link.


Can anyone give me some insight on exactly what is going on with this and maybe some sample code with how to dynamically place a value into a cell for this embedded spreadsheet?
 
You use regular Office automation to manipulate an Office document, this can be done prior to opening or while the document is opened with this control. The only link to this is the ActiveDocument property which is type Object, if you for example have opened/created an Excel book you can cast to type Excel.Workbook. (or Microsoft.Office.Interop.Excel.Workbook) Similar to this code:
VB.NET:
        Me.AxFramerControl1.Open("d:\booktest.xls")
        Dim xlBook As Excel.Workbook = Me.AxFramerControl1.ActiveDocument
        Dim xlSheet As Excel.Worksheet = xlBook.ActiveSheet
        xlSheet.Range("a1").Value = "value"
 
Sorry if I'm a bit dense here, but I'm still having some trouble understanding the working of the ActiveX.

My goal is this:

1. An application that runs an indeterminate number of cycles. With each cycle, it records some string results into a two dimensional array.

2. When the user clicks a 'View Log' button, the app creates a new form and a new instance of an Ax Spreadsheet and adds the control to the form. Assuming all resizing and locations are taken care of, all I have left to do is drop the values stored in the array into the activex spreadsheet.

Are the only references I need the COM references for office object, office control, excel object? Is there a reference for the Axframercontrol?

Again, sample code could be very helpful.

Thanks.
 
The 'dso framer' control you add first to your toolbox, then when you add as control to form it will generate the necessary references and interops. If you have to you can then remove the control from form again and add it dynamically through code instead (but why?), now that the project have all the necessary references and interops.
 
Back
Top