LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing continuously to excel

Solved!
Go to solution

Well, by looking at the "code-you-failed-to-post", I can "make a guess" at your error.  Assuming you are starting with an empty file (i.e. your Program is supposed to generate a new file, writing one line per loop and therefore creating an N-line .CSV file when you loop N times), I'll guess you didn't use a Shift Register to handle the Append to File input.  Since you are using LabVIEW NXG, which I haven't installed (and which I'm guessing many other Forum users aren't using), I'll allow "pictures" (LabVIEW Snippets) to pass VIs back and forth.  Here's how I'd do it:

Make CSV.viMake CSV.viand here's what it might produce (as a text file):Test.csvTest.csv

Bob Schor

0 Kudos
Message 11 of 18
(1,841 Views)

Dear Bob,

 

Thank you for your response and for taking the time to write this example.

You're right that I did not use a shift register in my tests. Honestly, I don't see how it çan be useful on the "append to file" input as it simply means false on the first iteration and true thereafter.

 

Anyhow, I tried to replicate your example on LabVIEW NXG and it still does not work: only the last line is présent in the file.

For some reason, I cannot append the .gvi file, so here is the image of my diagram

testwriteDMF.png

 

0 Kudos
Message 12 of 18
(1,832 Views)

As I don't have NXG installed, I can't comment on your VI (or check how it is supposed to work).  But here is the Help for Append to File? from Write Delimited Spreadsheet:

Write Delimited Spreadsheet HelpWrite Delimited Spreadsheet Help

If you leave this unwired, it stays False, so every time through the loop, you (over-) write a new file, meaning the final result has only the entry from the final loop iteration.  You want it to be false initially, as you are creating a new file, but for every other iteration, you want it to be True.  The Shift Register does this for you.  If NXG's analogous function works the same way (I can't tell), then it should "work the same way".

 

One question -- the Write Delimited Spreadsheet function I used had two inputs, a 1D input (which I used, as I was generating one line each time to be appended) and a 2D input.  The "Wire" you are showing in your Post looks like a double-line, which in LabVIEW means 2D array.  Aren't you building a 1D or 2D array?  Can you try using a 1D array?

 

Bob Schor

0 Kudos
Message 13 of 18
(1,824 Views)

Hello Didier,

 

Unfortunately Bob's explanation is only correct for LabVIEW "Current Gen". I tested the functionality of Write Delimited Spreadsheet in NXG and found that it differs for NXG.

 

The Write Delimited Spreadsheet node in NXG is a high-level file access VI that opens a text file, writes data into it, then closes it. As it writes additional header information, it does not append data to an existing file, but replaces the whole file every time. I did not find a difference in behavior using false or true for "append to file".

2019-03-07_16-46-29.png

 

I'd recommend managing the file writing yourself:

2019-03-07_16-54-38.png

 

As a csv file is just a plain text file, you can use the approach shown above to stream data into one.

 

I attached my gvi in a zip file (I could also not attach a gvi file, will flag this with NI).


Ingo – LabVIEW 2013, 2014, 2015, 2016, 2017, 2018, NXG 2.0, 2.1, 3.0
CLADMSD
0 Kudos
Message 14 of 18
(1,814 Views)

Thanks, ikaiser, for testing that (a) the NXG Function has an "Append to File" input (as I noted, I don't have it installed, so I can't comment on it), and (b) confirming that it Fails to Function "as advertised".  I'm going to report this as a Bug.

 

Bob Schor

0 Kudos
Message 15 of 18
(1,810 Views)

No worries, I already filed the bug report myself (-:

 

(And filed one for the forum software as well).

 

 

Note: I found some more about the NXG functionality. I used a shipped example VI. Functionality is similar to Didier's code. Wiring a 1D array, the function is labeled "Write Delimited Spreadsheet (Waveform)", and seems to ignore the wish to append data. I ran the gvi multiple times before taking the screenshot:

2019-03-07_17-16-53.png

 

Wiring a 2D array however, the function is labeled "Write Delimited Spreadsheet (DBL)", and works as expected. Please note that the first lines of the file are from the previously executed 1D array test:

2019-03-07_17-17-35.png


Ingo – LabVIEW 2013, 2014, 2015, 2016, 2017, 2018, NXG 2.0, 2.1, 3.0
CLADMSD
Message 16 of 18
(1,805 Views)

Thank you very much ikaiser,

 

This is exactly what I observed. The "Write delimited Spreadsheet" node works perfectly writing a 1D or 2D table when used outside the loop.

I was hoping to use it within the loop with "Append to file" checked, writing the last measured value at each itération but it does not work. On LabVIEW 2017, I was using the express v.i. for this purpose and it worked perfectly.

Hope that NI fixes the bug rapidly.

In the meantime, I can use your solution with lower level nodes without much of a complication

Many thanks to you and Bob

 

Message 17 of 18
(1,773 Views)

Accidentally, as I was playing again with the "Write delimited Spreadsheet" node, I notices that the code was doing its job perfectly when the data is presented as a 2D table as in the example below.

Then the "Append to file" makes the différence when checked.

I still think it is a shame that it does not work with a single value or a 1D table without warning

But at least I found my way out

testwrite2.png

Message 18 of 18
(1,768 Views)