LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing Trace Info to and Opening an Excel File on command

I am currently using a Read Traces (numeric) vi to collect values from Tags and output them to a XY Graph. Alongside the graph on my front panel, I would like a boolean control to command (when true) LV to write the data to a spreadsheet and open that spreadsheet so it appears on screen, ready for the user to view and then save the excel file where he/she would like.

Is this possible? I am a little unsure what File I/O functions I need in order to achieve this? I have tried using the "Write Traces to Spreadsheet vi" available in the DSC module, but haven’t had much success. I have attached my code to show you how far I have got.

Any help with this problem will be very much appreciated.

Thanks,

Stuart Wilson

0 Kudos
Message 1 of 10
(4,779 Views)
I don't have the DSC module but if you want to write a native Excel file, you're using the wrong function. Write Traces to Spreadsheet creates a tab or comma separated text file. Excel can open these with no problem but the function has nothing built-in to open the file first and then save. The function will open a file dialog in which the user can select the path and name and then the file is saved there. If you really want to open Excel, look at the shipping example called Write Table to Excel. This uses a 2D string array so you could convert the trace data or modify the example. And, you need to put your function inside a case statement or event structure if you want a file saved on demand.
0 Kudos
Message 2 of 10
(4,747 Views)
Hi Stuart,
 
Could you post an appropriate data file that I can enter into the Database Path field on your block diagram?
This will allow me to run your code and try and find a solution that will work with the type of data you intend to use it with.
 
Thanks
 
Emma R
 
NIUK & Ireland
0 Kudos
Message 3 of 10
(4,725 Views)
Hi Emma, thanks for taking a look at this for me! What kind of data file are you referring to? One of the cx00000 files in the "data" folder? Please let me know and i'll post it on. Thanks, Stuart
0 Kudos
Message 4 of 10
(4,714 Views)

Hi Stuart,

I have written an example piece of code for you which has the basic functionaliy that you want.

The example plots random data to a chart. When the boolean is pressed this data is written to a spread sheet file and Excel is opened to display this data.

As it is a generic solution you need to replace certain items when you incorporate the structure into your code: Instead of writting the history data of a chart you can use the "write traces to spreadsheet.vi" to write the data. The automation of excel can then be used in the same way as in the example.

There is also an example available in the "LabVIEW Example finder" called "Write Table to XL.vi". This example takes the data from a table and cell by cell inserts it into an excel speadsheet. Which the operator can then save from within excel. However, this method is not the most efficient way to get data into Excel.

I hope this is helpful.

Emma R

NIUK & Ireland

 

0 Kudos
Message 5 of 10
(4,695 Views)
Hi Emma, i'm afraid i got an error when running your code - please see attached jpeg. But thank you for taking the time to look at this problem, ideally I would like the excel data download to match the parameters i'd set in my graph. So, if i set my graph to show previous 3 days data, then excel would show the corresponding time stamps and data for those last 3 days. Many thanks for your continuing support, Stuart
0 Kudos
Message 6 of 10
(4,683 Views)

Hi Stuart,

The error that you are getting is due to the fact that we have different versions of excel, I have Excel 2003. The following link details the error and it's solution.

 
This way you can still use any parts of my code that you do want to use.
 
Hope this helps
 
Emma R
 
NIUK & Ireland
0 Kudos
Message 7 of 10
(4,680 Views)
Hi Emma, the info link you sent tells me that i need to change the installation of my report generation toolkit to suit my vi, rather than how to change my vi to suit my installation. The link page also tells me my compatibility is wrong, but it doesn't tell me how to change it. For instance, I don't know how to change the installation set up of my report generation toolkit? Is the report generation toolkit an extra for labview or is it included in the standard package? I can't find any info on report generation toolkit in the help file? Could you let me know what steps i need to take to change your piece of code to suit my Windows XP set up? Sorry to be a nuisance, and thanks for any further help you are able to give me. Best regards, Stuart
0 Kudos
Message 8 of 10
(4,647 Views)

Hi Stuart,

As we have different versions of Excel currently the Automation refnum within the VI is trying to link to an invalid source.

To fix this yo need to change the Refnum link:

If you go into the VI, right click on the refnum icon located on the front panel. Select "Active x class" option and choose "Browse". This will open the "Select Object From Type Library" popup box. In the "Type library" drop down, look for "Microsoft Object Library" and select the version that is current on your computer. Click OK to apply the change.

This change should hopefully update through the rest of your VI.

Hope this is helpful

Emma R

NIUK & Ireland

0 Kudos
Message 9 of 10
(4,640 Views)
Hi Emma, thanks but i'm afraid that didn't work - I still get the same error message (see attached). I even tried changing the Automation Refnum input to the Automation Open vi but that just returned the following error message: "Invoke Node: contains unwired or bad terminal" and a broken arrow Any further suggestions on getting round this problem? thanks again, Stuart
Message 10 of 10
(4,622 Views)