Jump to content
Grv Chy

Export data from LabVIEW to Excel (.CSV) in real time

Recommended Posts

Hello ,

I am trying to Export data from LabVIEW to an Excel file(.csv) in real time. I Need to see the data in a real time , which are written in the Excel without Closing the Excel. my Problem is i can see the real time data writting in LabVIEW . But in Excel i can see the data only after stoping my LV program. Is there any way to watch real time data writting in each column the Excel. I have attached my LV program.

Write_CSV_date_time.vi

Share this post


Link to post
Share on other sites

What you want is to flush your output file occasionally.

File writes are buffered, and performed only when enough data has gathered, or the file is being closed.

In C, flushing is done by fflush(); for LV - someone else will have to answer.

 

Share this post


Link to post
Share on other sites

Yes, Mefistotelis . I want to see each data , which ar send to excel in real time in the excel sheet.

Share this post


Link to post
Share on other sites

There is a "Flush File" function in the "File I/O >> Adv File Funcs" menu that you can have execute after every write.  

However, If you already have Excel open to view the CSV file, I don't believe that Excel will automatically update your spreadsheet contents every time the file changes if that is what you're trying to do. I haven't tried that myself. 

If the above doesn't work, it may be that Excel doesn't constantly monitor the file and automatically update.  You could try using the "Refresh All" button in Excel under the "Data" menu, but you'd have to do this manually.  Additionally, you'd have to open your reference to the file with permissions configured in such a way that it doesn't block other applications from using the file if another already has it open.

Someone more experienced in Excel and actively monitoring file contents may be able to provide more info.

Share this post


Link to post
Share on other sites

Hello Bryan,

However, If you already have Excel open to view the CSV file, I don't believe that Excel will automatically update your spreadsheet contents every time the file changes if that is what you're trying to do. I haven't tried that myself.

--->>>>> yes i am trying to keep ma excel sheet open while data  are updating in real time, which i receive per second from LabVIEW.

Share this post


Link to post
Share on other sites

Excel actually locks the file so only it can edit it.  So if you close the file in LabVIEW, you will not be able to reopen it to add more data.  Yes, I have personal experience with this.

 

Since you are using a CSV, I would recommend something like UltraEdit.  UE edits backup files and it will let you reload files that have changed while you have it open.  I'm not sure if Notepad++ does the same.

Share this post


Link to post
Share on other sites

Thank you for the suggestion, Can you please elaborate it . If possible LV program, where you used this UE. 

Share this post


Link to post
Share on other sites

UltraEdit is just a text editor (a REALLY good one, in my opinion).  So I have had test results being saved to a text file and had the result file open in UE.  I can look all I want and then reload the file whenever I want to see the updates.

Share this post


Link to post
Share on other sites

Thank you for the explanation... but for me i must write the data in excel(.csv) and same time able watch the data update like i do in labview....

Share this post


Link to post
Share on other sites

CSV is a text file.  So why are you stuck with Excel?  It will not do what you want.  What's wrong with making another viewer?  Push back on this requirement to figure out what the real goal is.

Share this post


Link to post
Share on other sites

I'm not sure that you're going to be able to (easily) do what you want to do without some advanced programming to automate/manipulate Microsoft Excel (for instance, using ActiveX or dotNET), even then - I'm not sure it's possible to do what you're trying to do as it involves Microshaft software, over which LabVIEW will have limited ability to control.

I agree with 'crossrulz'.  Whomever is pushing this requirement may need to reevaluate the need for this functionality.

Share this post


Link to post
Share on other sites

You should use the Excel .NET API. You will see your data as it is added to the spreadsheet. 

Also, you can do this with OpenOffice/LibreOffice if you don't want to pay for Excel.

Share this post


Link to post
Share on other sites

I agree that you should probably push back a bit on the requirements.

If you want to get real weird with it, I've worked with a group that did all of their hardware interaction in LabVIEW, built that code into a DLL and then called it from an excel macro that was continuously running.

Share this post


Link to post
Share on other sites
On 7/2/2020 at 6:38 PM, jacobson said:

I agree that you should probably push back a bit on the requirements.

If you want to get real weird with it, I've worked with a group that did all of their hardware interaction in LabVIEW, built that code into a DLL and then called it from an excel macro that was continuously running.

Hello Jacobson, Can you please help me to get this DLL  and use it LabVIEw, may be you have that code.

Share this post


Link to post
Share on other sites
On 7/2/2020 at 6:01 PM, Gribo said:

You should use the Excel .NET API. You will see your data as it is added to the spreadsheet. 

Also, you can do this with OpenOffice/LibreOffice if you don't want to pay for Excel.

Hello Gribo, do you somthing like code or exmple, where i can see my data in real time. It will be very helpful for me.

 

Share this post


Link to post
Share on other sites

Here you go. 

This is not a production code. You will have to close references when you are done with a specific object.

2 things to note:

1. Excel, like VB is 1 based. 1st index is 1.

2. Don't leave an empty property node input. Wire a 'missing' type to any gray (optional) input that you don't use.

Excel sample.png

  • Like 1

Share this post


Link to post
Share on other sites
22 hours ago, Gribo said:

Here you go. 

This is not a production code. You will have to close references when you are done with a specific object.

2 things to note:

1. Excel, like VB is 1 based. 1st index is 1.

2. Don't leave an empty property node input. Wire a 'missing' type to any gray (optional) input that you don't use.

Excel sample.png

Thank you Gribo. I have attached my VI. But i got 2 Problem: 1. I was not able to insert property node "Type" > "missing". 2. I get error from my Invoke node "Add". Do you ha ve any idea??

Excel_Sheet.PNG

csv_update.vi

Share this post


Link to post
Share on other sites

Type object is in the System namespace. Click .NET connectivity -> Invoke node -> Select class -> System -> Type -> Missing

Share this post


Link to post
Share on other sites
4 hours ago, Gribo said:

Type object is in the System namespace. Click .NET connectivity -> Invoke node -> Select class -> System -> Type -> Missing

Great man it is working… Now i just Need to find out how can i write random number continously in each row and column in each 500 ms.

Share this post


Link to post
Share on other sites
On 7/2/2020 at 4:56 PM, crossrulz said:

CSV is a text file.  So why are you stuck with Excel?  It will not do what you want.  What's wrong with making another viewer?  Push back on this requirement to figure out what the real goal is.

Hello crossrulz,

The actual target is to see each data in .csv Format but i am not able to find real time update in .csv , when LabVIEW send a data in each Minute, it should be also updated in csv while it is opened. I Need to monitor each data send from LabVIEW while csv is receiving it. I am not able Keep open csv file and monitor while it is receiving data from LV.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.