Excel

From LabVIEW Wiki
Jump to: navigation, search

Firstly, do you really want to? Certainly Excel and LabVIEW have supported direct communication, whether by OLE, DDE, Active X, or Apple events (for those of us on the minority platform), for many years. (I used direct communication between LabVIEW 3.0 and Excel 4.0). The problem is that Microsoft changes the protocols with every upgrade to Excel. All your carefully crafted code breaks and needs to be redone. Consider the possibility of communicating instead through a tab-delimited text file. That will work with any version of Excel and a large number of other programs as well. LabVIEW supports tab-delimited text files (and other delimiters) with File I/O >> Read From Spreadsheet File, File I/O >> Write To Spreadsheet File, and String >> Spreadsheet String to Array.

Other issues can be incompatible versions between the development system and the target system and does the target machine even have Excel on it? When developing for a general audience, stay with the common denominator.

And what if I still want to write to Excel? Well there are essentially two options. One is to buy a commercial product such as XL-VIEW or the Report Generation toolkit.

The other is to experiment with Automation. To summarise this process you need to open an automation connection to Excel, and use invoke and property nodes to open a workbook, and then a worksheet, and then you are ready to write to a cell. The Developer Zone on the NI web site has several examples on accessing Excel. Furthermore there are ready made snippets in the LabVIEW examples directory (examples\comm\ole-excel8.llb).

You can also use examples to write directly to excel (C:\Program Files\National Instruments\LabVIEW 2009\examples\comm) there is an excel examples library which may be helpful. Or just write to a .csv file and use the command line text to open that file with excel. With pre-excel2009, where they changed all the menu styles, you can simulate a keypress (search for the code example that calls user32.dll keybd_event) to get all the menu's to operate and create graphs, label graphs etc...