LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading an excel file (.XLS) using LabWindows/CVI ActiveX controller

Hi, I need to read an excel file from LabWindows. I know that to do this is by using the ActiveX controller for Excel. I took a look to the help examples to do this but it is not easy to understand. I don't know if I have to launch excel just for reading a file (there is no tutorial that explains how to use the ActiveX fucntions). Can anyone tell me how to just read an excel file? A simple code example could help. Thanks in advance
0 Kudos
Message 1 of 3
(6,001 Views)
What help did you look at? Did you review the sample projects that ship with CVI, excel97dem.prj or excell2000dem.prj (in ..\CVI\samples\activesx\excel)?
The samples are pretty straightforward. The code snippets below are taken from the example just to highlight some of the meat of the code. Run the example to see it work, don't just try to run the code below.
// If Excel isn't already running, you need to launch it:
error = Excel_NewApp (NULL, 1, LOCALE_NEUTRAL, 0, &ExcelAppHandle);
// If Excel is already running, you can connect to it (without relaunching it):
error = Excel_ActiveApp (NULL, 1, LOCALE_NEUTRAL, 0, &ExcelAppHandle);
// After that you can get the handle to the Excel workbooks
// and open an existing file:
error = Excel_GetProperty (ExcelAppHandle,
NULL, Excel_AppWorkbooks,
CAVT_OBJHANDLE, &ExcelWorkbooksHandle);
// Open existing Workbook
GetProjectDir (fileName);
strcat(fileName, "\\exceldem.xls");
error = Excel_WorkbooksOpen (ExcelWorkbooksHandle, NULL, fileName, CA_DEFAULT_VAL,
CA_DEFAULT_VAL, CA_DEFAULT_VAL,
CA_DEFAULT_VAL, CA_DEFAULT_VAL,
CA_DEFAULT_VAL, CA_DEFAULT_VAL,
CA_DEFAULT_VAL, CA_DEFAULT_VAL,
CA_DEFAULT_VAL, CA_DEFAULT_VAL,
CA_DEFAULT_VAL, &ExcelWorkbookHandle);
// See the ReadDataFromExcel function in the sample files to see two ways of reading data:
// 1) Read one cell at a time.
// 2) Read a range into a SAFEARRAY.
0 Kudos
Message 2 of 3
(6,001 Views)
Hi,

You don't necessarily must have Excel launching in a separate window to view the excel file. You can have an ActiveXcontainer in your UI that holds an instance of Excel with the document you want to show.

There is an example that ships with CVI that does this type of integration with a web browser; you can find it in: C:\Program Files\National Instruments\CVI70\samples\userint\activex\WebBrowser.prj

you can use the "Create ActiveX controller" from the tools menu to automatically generate a set of function panels to control the ActiveX object.

The procedure would be somethig like this:

1.-Insert an ActiveX conteiner in the UI from the pallete.
2.-Assign excel to that control by selecting it from the list. (It will open Excel in that contain
er)
3.-Use the Wizard to generate the function panels.
4.-Use the functions that you get in the instrument driver to control the excel instance that you have.


I hope this helps.

Regards,

Juan Carlos
N.I.
0 Kudos
Message 3 of 3
(6,000 Views)