From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing in Spreadsheet (Columns)

Solved!
Go to solution

Good afternoon everyone,

 

I have encountered a slight problem which would like to clarify. I am reading data from my PLC and writing it to excel which is achieved successfully. Nevertheless I want the data to be written in different columns and have tried various combinations but the end result seems to be the same which is, the two different data are written in the same column. Attached are my files, please do give me an insight as to were I am making a mistake. Thank you very much for your help.

 

Sincerely,

Carlos Torres

0 Kudos
Message 1 of 4
(2,522 Views)

If you just want to write two values to a CSV file in separate, adjacent columns, and have the next iteration be on the next line, use the Format to String node, drag the input to 2 elements, and use the format string input as "%f,%f\n" (without quotation marks). This will give two floating point numbers separated by a comma (for comma separated variable file 😉 ) and terminated by a line feed (i.e. new line) character.

 

You can open the detailed help via Context Help (Ctrl-H) hovering over the Format to String node and look for more detail on the format specifiers, for example to specify number of decimal places.

 

If you have a lot of inputs (more than 2) then Build Array and an auto-indexed For loop might be preferable. Then you could do something like this (it will work for 2 inputs also, but it's somewhat overkill there):

Example_VI_BD.png

Edit: You might not want the trailing comma - in that case, you can use the following:

Example_VI_BD.png

 

 


GCentral
0 Kudos
Message 2 of 4
(2,498 Views)
Solution
Accepted by topic author CarlosT

1. You do not need to set the file pointer every iteration.  In fact, you do not need to at all since you are setup to create or replace.

2. All you need to do is Build Array and then Array To Spreadsheet String.  Get rid of the extra stuff in there (ie the creating of the 2D array).  The Array To Spreadsheet String will accept the 1D array and will put the End Of Line at the end of the string.

3. Since you are saving to a CSV, you should use the comma as the delimiter.  If you want to keep using the tab, then save the files as TXT.  This will help Excel decode your data properly.


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 3 of 4
(2,461 Views)

Thank you very much crossrulz in deed this is a viable solution, I had tried it but my mistake was in the delimiter once I used the on you recommended everything works just as I need it.

 

Cheers

0 Kudos
Message 4 of 4
(2,436 Views)