LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

write data to CSV

Solved!
Go to solution

Hello,

im using Write Multiple Columns With Write to Spreadsheet File VI - NI Community this example to write the data in csv file but im not getting results as expected. I have 3 output numbers and i want repeat while loop multiple for multiple iterations as im attaching here. but when i run the vi im getting only one value of iteration  even im giving 5, 10, 15 or more iterations  as input moreover the written values in also is only in one columns not in the different columns. can someone tell me what is the issue in it? and for corrections 

 

thank you

Download All
0 Kudos
Message 1 of 12
(9,660 Views)

Hi jeet,

 

the VI does exactly what you programmed to do!

 

You write the header row each iteration - and even more worse: you create a new file with each iteration…

 

You need to understand those examples before you start to modify them!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 12
(9,652 Views)

Hi,

 

With the first use of "Write to spreadsheet file" you are creating the file and adding value.

Second use you are adding value.

 

Then you are going to the next loop iteration and do it again, including the creation of the file by overwriting the old one.

 

You should create your file outside of this specific loop and only adding values there.

 

add_to_file.png

Message 3 of 12
(9,651 Views)

The red Cross means this VI is too old, it was created for LabVIEW 2012, you can replace the with the following VI

FrankenChino_2-1662385677462.png

FrankenChino_0-1662385611103.png

FrankenChino_1-1662385631936.png

 

Regards,

FrankenChino

Message 4 of 12
(9,639 Views)

Hi, gerdw

i made changes as you said.. now im getting data for all the iterations but not in the columns. can you tel me what is the wrong in the vi??? attaching the changes and output .. 

 

thanks 

Download All
0 Kudos
Message 5 of 12
(9,617 Views)
Solution
Accepted by topic author jeet4230

For a csv file this is OK.

The interpreter has to know the delimiter and do the work to make it into columns. For a csv it will do it each time it sees a comma.

 

Now, depending of the file extension, your Excel will open it as a .xlsx and not doing that work.

To do it manually in Excel : Excel => Data => Convert => Delimiter = comma.

 

You can also choose the delimiter in LABView with a tabulation as delimiter and then no work to do in Excel, but your file is no more a real .csv.

Message 6 of 12
(9,607 Views)

Hi,

 

change the input as 2D array, change the data input also as 2D array as well, just try out, so you will finger out the mapping of columns and rows.

 

Regards,

FrankenChino

FrankenChino_0-1662388921434.png

 

Message 7 of 12
(9,597 Views)

this worked thanks 

0 Kudos
Message 8 of 12
(9,582 Views)
Solution
Accepted by topic author jeet4230

Let me suggest an alternative (that example is actually pretty bad).

 

You should not be using the Write To Delimited File inside of a loop.  That VI opens the file, sets the file pointer, writes the data, and closes the file each time it is called.  Instead, create the file before your loop, write inside as much as you want, and then close the file after the loop.  This is SOOOOOOOO much more efficient.

 

Doing this will also remove the need to deal with arrays like you are.  I chose to use the Format String instead of the concatenating as I think it is cleaner.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 9 of 12
(9,506 Views)

hello,

im attaching what im trying to do.. im writing data to CSV  i as i explained before the and its working now i want to add one function in it. i want to use event structure  or any similar function so if i press button save data then only it should save the data or else it should stay idle and it should not save the data in CSV file. can someone tell me how can i do it?

 

thank you

Download All
0 Kudos
Message 10 of 12
(9,436 Views)