LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Embedded ActiveX Microsoft Office Spreadsheet

Could someone direct me to example code (or something) for using an embedded Active X Microsoft Office spreadsheet?  There are plenty of examples for using ActiveX to read, write, etc. to Excel; I need help with an ActiveX object (Create>>ActiveX>>Microsoft Office Spreadsheet 10.0 from OWC10.dll) that is inserted into my UIR.

 

Tx,

Randall

 

Also, I am having trouble searching the site.  For example, if I Search “Entire Site” or “All Support Resources” on keyword “Microsoft Office Spreadsheet” I get no results.  If I Search within “NI Developer Zone” on the same keyword, I get a result. 

 

 

 

0 Kudos
Message 1 of 6
(4,973 Views)

Hey Randall,

The only way I have found to create an embedded excel activeX object that works with the Excel 10.0 object library is to use a different spreadsheet control than the one you are using.  Instead of going to " "Create>>ActiveX>>Create Control>>Microsoft Office Spreadsheet 10.0 from OWC10.dll" go to " Create>>ActiveX>>Create Document>>Microsoft Excel Spreadsheet from OLE32.dll"

Note the extra step in there that allows you to create a document.  One you do this, you can use the "GetObjHandleFromActiveXCtrl" function on this control and it will return the 'Workbook' object handle to you.

This document doesn't look as pretty as the one created from the OWC10.dll but it has all of the Excel functionality and it seems to be the only one that actually works with the Excel 10.0 object library.  If you find a way to get the OWC10.dll control to work let me know, I'd be interested to see how you did it!  But until then you will have to use the one created by OLE32.dll Robot Indifferent

0 Kudos
Message 2 of 6
(4,942 Views)

I got OWC10.dll to partially work.

 

Once I inserted the Spreadsheet, I created an ActiveX controller from the same DLL (Tools>>Create ActiveX Controller).  The resulting .fp file contains several callbacks I cannot get to work.  However some of the callback do work.  Below is an example that inserts the value 3.3 into the active cell of the active sheet.

 

 

// OWC10 is the Instrument Prefix I used when creating the ActiveX Controller

VARIANT VariantValue; 

OWC10Obj__Range Cell; 

OWC10Obj_Sheets Sheet;

 

//Gets handle to Spreadsheet; serves as workbook handle

GetObjHandleFromActiveXCtrl (panelHandle, PANEL_SPREADSHEET,&workbookHandle);         

 

//Gets handle to active cell

OWC10_ISpreadsheetGetActiveCell (workbookHandle, NULL, &Cell);

 

//Creates a VARIANT with value 3.3                          

CA_VariantSetDouble (&VariantValue, 3.3);

 

//Writes value into active cell

OWC10__RangeSetValue (Cell, NULL, CA_DEFAULT_VAL,VariantValue);

 

This is about all I've been able to get it to do since several of the callbacks do not work.  

Let me know if you can do much else with this. 

0 Kudos
Message 3 of 6
(4,938 Views)

Hello SRB,

In particular, what kind of behavior are you looking for with the ActiveX control/document?  I was able to programmatically read and write to cells using the Excel control and Excel document.

Thanks.

Wendy L
LabWindows/CVI Developer Newsletter
0 Kudos
Message 4 of 6
(4,913 Views)

Wendy; Thanks for the post.

 

I am trying to get the ActiveX spreadsheet (which is inserted into the UIR) to respond the same way an Excel spreadsheet would.  The embedded spreadsheet works fine when used in other, non NI, programming environments.  The majority of the callbacks (generated using the Create ActiveX Controller) do not work (using CVI 7.0 with Office 2002 or 2003). 

 

In particular I would like to:

1.      Be able to write to the spreadsheet.  I’ve only found how to write a single value to the active cell of the active sheet.  Or read in a text file to the active cell.

2.      Graph Data.  The callback within ChCharts, such as ChChartsAdd do not work.

 

From the error value returned I think the problem may be an invalid handle.  The handle returned by GetObjHandleFromActiveXCtrl works for some of the callbacks but not others.

 

If you have code that can do anything more than what I posted previously (especially if it can graph) please post it!

 

Thanks

 

 

0 Kudos
Message 5 of 6
(4,905 Views)
Hello SRB,
 
I was able to insert a range of numbers and insert a chart into an embedded Excel document.  I started off with the excel2000.prj shipping example, and instead of calling Excel to load an XLS file on disk, I retrieve the object handle to the ActiveX document on my CVI panel.  This object handle is a handle to an Excel Workbook.  From there, the function calls should work if you pass in the appropriate handles.  The only caveat I ran across is that the Excel_RangeActivate doesn't seems to work with Excel ActiveX documents, but I would need to do some further research to find the exact cause of the discrepancy ... Either way, you should still be able to input data into a particular range without this function (as you will see in the code, this function call is commented out).
 
I have attached the code for your review.  I hope it helps clarify things.
 
Thanks.
 
 
Wendy L
LabWindows/CVI Developer Newsletter
0 Kudos
Message 6 of 6
(4,873 Views)