LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to continuously write multiple variables to one spreadsheet file?

Solved!
Go to solution

I am trying to write a program in LabVIEW that will continuously write three variables (Temperature (F), Temperature (C) and rate of change of temperature over change in time (C/s)) to a single file, in 3 seperate columns, as well as the corresponding time.  I have been working on figuring it out for a few hours and can't figure anything out.  I was wondering if it is possible, and if so, how?

0 Kudos
Message 1 of 12
(7,037 Views)

All you need is append a tab delimited row of four values with each update. Where exactly do you have a problem?

Message 2 of 12
(7,032 Views)

I'm not entirely sure what do you mean by append a tab delimited row of four values with each update, as I am very new to the software.  First of all, which function do you suggest I use?  My whole program is inside of a while loop structure.  I have formed the three output variables I want into a 1-D array using the build array function and connected that array to the Write To Spreadsheet File.vi function, but it seems like this function does not continuously write the values;  I have to save it into a new file each iteration.  I also tried connecting the array to a Write To Measurement file.vi function, saving to an excel file format, but that seemed to write each of the three variables in the same column.

0 Kudos
Message 3 of 12
(7,018 Views)

Hello CrashMcLars1, and welcome to the forum!

 

The Write to Spreadsheet File function has an input named "append to file?" that defaults to false.  If you wire a Boolean True value to this input, your values will be appended to the file rather than overwriting it. 

 

Also- Ctrl+H or the question mark in the upper right corner of your block diagram will launch the Context Help window- very handy for seeing how a function works and what it expects for inputs!

 

Regards,

Tom L.
Message 4 of 12
(7,009 Views)

"Write to spreadsheet" has a "append?" input. Wire a TRUE to it and it will append. Here's a very simple example.

 

 

Message 5 of 12
(7,008 Views)

Note that "write to spreadsheet file carries a lot of baggage, so if you are writing at a relatively high rate, it is better to open the file before the loop, append inside the loop as correctly formatted plain string, and close the file at the end.

 

You can open "Write to spreadsheet" by double-clicking and you'll see that it opens and closes the file with every write, which can be expensive and unecessary.

 

(If you need to write at a even higher rate, you should use a binary file, but that is beyond the scope of this discussion.)

Message 6 of 12
(7,003 Views)

@altenbach wrote:

... so if you are writing at a relatively high rate, it is better to open the file before the loop, append inside the loop as correctly formatted plain string, and close the file at the end.


Here's a quick example for that.

 

 

 

Of course you should format the time stamp according to your specific requirements.

Download All
Message 7 of 12
(6,999 Views)

Awesome! the first file you have sent works very well for me and I have almost got what I want.  If I save it as a text file and open it in notepad, I get 4 seperate columns.  My only problem now is if I try to save it as an excel file, I get an error message when I try to open the file saying "Excel found unreadable content in 'Test2.xlsx'. Do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes."  I clicked yes and Excel presents me with a dialog saying "Excel completed file level validation and repair. Some parts of this workbook may have been repaired or discarded."  So I end up with a blank excel spreadsheet.  I understand I can copy and paste the variables from the text file into an Excel file, but ideally I would like to just be able to save it into an Excel file to begin with.  Is there another way I could import the data into Excel? Is there some sort of additional software I need for Excel to properly read the data?  Anyways, Thanks altenbach and outlaw for all the help so far.  I really appreciate it.

0 Kudos
Message 8 of 12
(6,971 Views)

Don't save it as an .xlsx.  It is not an excel file.  It is a text file.

 

So save it as a .txt or a .csv

Message 9 of 12
(6,968 Views)

Ok so if I want this data in an excel spreadsheet, what would be the best way to do that?

0 Kudos
Message 10 of 12
(6,963 Views)