LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I add headers and timestamp to spreadsheets when using Write To Spreadsheet File.vi?

Firstly, I've seen many examples on here using Write to Text File and have an idea of what you're going to tell me, but I'm using Write To Spreadsheet File which has a handy 'append' function (I've had no luck at all getting Write To Text File to append, even if using Set File Location).  Write to Spreadsheet File needs array data, and every example I've seen has the timestamp/headers being sent as string.
 
Here's the simple VI I'm playing with, adding and subtracting in an attempt to get at least the output file to look like it's formatted the way I need it to be.  What I need is column headers, and a time stamp on each row of data.
 
Can someone give me some direction here?  Much appreciated in advance!
 
 
___________________________________________________________________
Still confused after 8 years.
0 Kudos
Message 1 of 11
(4,892 Views)

If all you want is a header than I suggest putting a Write to Text File VI outside your loop and write the header to the file.  Then send that path in to the loop and use the Write to Spreadsheet File VI.  Make sure you have data flow in place to ensure that the header write finishes first.

The above will work but I have to mention that using the high level VIs like that is very in efficient.  You are opening and closing the file in a loop, which is slow.  However, you also have a 1 second wait, so I am not sure how important timing is in your actual application.

0 Kudos
Message 2 of 11
(4,889 Views)

Timing doesn't have to be spectacularly fast.  I can take data every 5 seconds and write once every five minutes.

What kind of setup would you recommend to make it cleaner?  Which combination of VI's?

 

In addition to header data I also will need a time stamp on each row.

Message Edited by Ralph@NES on 05-31-2006 11:21 AM

___________________________________________________________________
Still confused after 8 years.
0 Kudos
Message 3 of 11
(4,888 Views)
And forgive me for what may be a dumb question, but what's data flow?
___________________________________________________________________
Still confused after 8 years.
0 Kudos
Message 4 of 11
(4,883 Views)

Ok we have a couple issues.  Take a look at the attached VI and you will see how you can open the file once and then continue to use its reference.  I then write to it in a loop, and then close it at the very end.

 

As far as the data flow question that is a much bigger question.  Basically that is how LabVIEW executes code.  I would suggest searching the help, taking the tutorial and looking on the forums for more info on it.  I will give you a quick run down here though.

Look at the attached Data Flow example.  Notice that the addition occurs first and then the subtraction.  The reason is due to data flow.  In LabVIEW a function will occur as soon as all of its inputs are available.  So as soon as you run that simple VI the addition has its 2 inputs, x and y so it can execute.  The subtraction must wait for the data to flow to it from the addition before it can execute.  Therefore it goes second.

Makes sense so far.  Now it can get a little more complicated with multiple functions ready at the same time.  So look at the second VI.  Notice that the addition subtraction section is totally separate from the multiple divide section.  So in this VI as soon as you run it both the addition and the multiplication have all their inputs.  So both can run and you have no way of knowing which will execute first.  That may be ok, you just need to watch for it.

Now lets assume that the addition occurs first this time.  After it executes the multiple has all its inputs still, and now the subtraction does as well.  So, theoretically either function could execute now.  LabVIEW could do the subtraction or the multiplication.  Both are valid.

The above examples of data flow are obviously simplified but the same occurs for loops, and other functions.  In the code I sent you because I pass the error cluster and fiel refnum into the while loop we are sure that the open and header write will occur before the loop starts to iterate.  Therefore I know that the header will be before the data in the file.

Download All
0 Kudos
Message 5 of 11
(4,875 Views)
Hmm.  I think I get the general idea.
 
Where the 'I am a header' is at, is there some way to format that so that it becomes column headers?
 
I had a very similar flow going with the attached VI but I'm not sure how the data flow is being executed.  I could be just lucky on mine.
 
 
___________________________________________________________________
Still confused after 8 years.
0 Kudos
Message 6 of 11
(4,870 Views)
 

Message Edited by Evan on 05-31-2006 11:03 AM

0 Kudos
Message 7 of 11
(4,867 Views)
To answer your question you can make them headers by replacing the "," with tabs.
 
As far as the dataflow.  Your VI is most likely ok, but to be a real stickler notice this.  Both your while loop and your Write function have all the inputs they need.  Ie the path constant.  So you have no way of controlling which starts first.  So there is a chance, though slim, that your loop would start first.  It could even put data into the file, before your Write header section occured.  That would be an exceptable series of events for LabVIEW.
 
So to ensure the header stuff is done first simply wire the error out of the Write VI to the loop.  Therefore the loop has to wait for the Write VI to finish first.

Message Edited by Evan on 05-31-2006 11:06 AM

0 Kudos
Message 8 of 11
(4,868 Views)

Thanks for bearing with me on this Evan.  I do appreciate it.

 

Here's what I've got mocked together now.  It's outputting basically what I want, but there's this annoying tendency in the output .txt file to put the time stamp on a separate line as the temps.  I've rearranged it a couple different ways and it still makes the time stamp go to the next line even though the preceding string is a space or tab.

If I can get it to make that all linear, then I'll be close to my goal as far as output file is concerned.

Notice my structure at the bottom with the concatenate strings?  That was the way I approached the header spacing.  You mentioned something about commas, is there a better way than what I've butchered together?

___________________________________________________________________
Still confused after 8 years.
0 Kudos
Message 9 of 11
(4,860 Views)

The new line is coming from the array to spreadsheet function.  It adds a new line delimiter at the end of each string.  An easier fix may simply be to strip off the last character of the spreedsheet string though.  See the attached.

0 Kudos
Message 10 of 11
(4,848 Views)