LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

reading excel file dynamically

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.

0 Kudos
Message 1 of 26
(3,814 Views)

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.

 

0 Kudos
Message 2 of 26
(3,809 Views)

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

0 Kudos
Message 3 of 26
(3,769 Views)

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.

0 Kudos
Message 4 of 26
(3,759 Views)

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

0 Kudos
Message 5 of 26
(3,748 Views)

@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

Download All
Message 6 of 26
(3,742 Views)

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.

Message 7 of 26
(3,719 Views)

hey ben, is it possible to save ur VI to version 12 instead, my comp has only version 12. thanks

0 Kudos
Message 8 of 26
(3,703 Views)

And Ravensfan, is it possible to send me a copy of your VI? interested to see how yours works.

0 Kudos
Message 9 of 26
(3,701 Views)

I don't have any VI's for this topic.

0 Kudos
Message 10 of 26
(3,691 Views)