06-26-2017 10:44 PM
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
Solved! Go to Solution.
06-26-2017 11:41 PM - edited 06-26-2017 11:48 PM
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):
Edit: You might not want the trailing comma - in that case, you can use the following:
06-27-2017 06:19 AM - edited 06-27-2017 06:20 AM
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.
06-27-2017 09:24 PM
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