04-22-2015 10:18 PM
Is there any possible way to read new data from excel file into labview as I enter new data into the excel sheet. Hope someone can help me on this asap.
04-22-2015 10:31 PM
First thought. No. Trying to open an excel file in LabVIEW while you have it open in Excel will give you a file locked error.
Second thought. Maybe. If it is open in Excel, you might be able to use ActiveX to get a reference to the Excel Application and the worksheet and pull the data out of it that way.
04-23-2015 09:31 AM
Well, I thought that was a good question, so I "did an experiment". I opened an existing Workbook and (using an Event structure) read selected rows into LabVIEW. While the Workbook was open (in LabVIEW/Excel -- I used the Report Generation Toolkit's New Report to open it in Excel), I edited a row, then asked LabVIEW to read in that row. I got the edited version.
So, the answer is that the Report Generation Toolkit and its functions are capable of opening a Workbook in Excel, reading and writing to the WorkBook, and allowing the user to make changes to the Workbook at the same time. I'm pretty sure (but, I confess, I haven't tested this) that if I were to read one or more rows from Excel with LabVIEW, edit the rows directly in Excel, and then write the LabVIEW data back over the edited rows, that my edits would disappear -- the Principle of "He Who Writes Last, Wins".
Bob Schor
04-23-2015 10:40 AM
Bob, thanks for taking the time to experiment. I haven't used RGT myself, so it hadn't crossed my mind. It uses activeX calls under its hood to make the connection to Excel sheets. So the activeX methods seem to work and the Report Generation Toolkit is the package that can make that easier for people to do.
04-23-2015 11:54 AM
About 5 years ago, I "inherited" a LabVIEW 7 Real-Time project that used Excel to control a behavioral experiment. It was sloooowww, and very complicated. A colleague suggested that using ActiveX would speed things up, so I gave it a whirl. It was faster, and by suitable encapsulation in routines of my own making, I could almost make it usable, but trying (even then, while Microsoft was still actively supporting it) to master the arcanery of ActiveX was a struggle.
About three years ago, I started "redeveloping" this application in LabVIEW 2011 (and up). I'd earlier seen the new Object-oriented Report Generation Toolkit, and while I didn't like NI's Example code (I submitted a "Revised Example" here a year ago), for most things I appreciated NI's "encapsulation" ideas. I've basically abandoned my original attempts to use ActiveX (except when you really need to do something "funky") and find the Report Generation code very logical, easy to use, and fast.
Bob Schor
04-23-2015 02:02 PM
@b9 wrote:
Is there any possible way to read new data from excel file into labview as I enter new data into the excel sheet. Hope someone can help me on this asap.
Using ActiveX you can use a Worksheet Change event and create a callback vi. See attached VIs.
Ben64
04-23-2015 09:27 PM - edited 04-23-2015 09:31 PM
One of the difficulties with Excel ActiveX methods is that MS seems to constantly restructure there activeX properties and methods on every version of MSOffice. So what runs on one system may break on another. Or even if it does work, you might have to recompile and save the VI's in the event you wrote an app based on Excel 2007 (for example) and then you try to run it on a system with Excel 2010, even if you didn't even change your LabVIEW version.
Even playing with the attached VI, it loads RGT that is installed on my PC. (Heck dropping a new RGT subVI on a blank diagram will do this.) When I go to close LabVIEW, it will ask me to save the changes in a whole list of RGT subVI's. I didn't change them. I didn't even touch them. Probably the RGT was installed with LabVIEW and they were compiled with one version of Excel ActiveX methods and objects. When I open it on mine with probably a different version of Excel than National Instruments add when they build the installers, everything recompiles automatically. Then it demands to save those changes when I close LV.
Opening Ben's VI above, when I close I get VI recompiled, and External Component modified since last VI saved. All for a LV 2014 VI that I also opened in LV2014. For reference, Office 2010 is the version installed on my PC.
I just find it rather irritating, and one of the reasons I don't try to look to hard for an application where I need to work with Excel and ActiveX. And if I did, I'd try to keep it simple and stay away from RGT.
04-23-2015 10:33 PM - edited 04-23-2015 10:34 PM
hey ben, is it possible to save ur VI to version 12 instead, my comp has only version 12. thanks
04-23-2015 10:42 PM
And Ravensfan, is it possible to send me a copy of your VI? interested to see how yours works.
04-23-2015 10:58 PM
I don't have any VI's for this topic.