03-15-2021 10:38 AM
Hello everyone.
I'm creating a program which has to provide a spreadsheet file (a .csv file to be opened on Excel) with a few values recorded as an output after the program runs.
I have 3 parameters which should be shown as:
Parameter 1 Parameter 2 Parameter 3
Value Value Value
Aswell as values of average energy consumption for each speed at which the compressor im working with can operate, which should be shown as:
Speed [RPM] EC [W]
4500 Value
4200 Value
... ...
1800 Value
I'm able to create the .csv file with the values I need, but if you open the file, the values are all sorted weirdly (not separated by column).
I have tried many different approaches to this, but I can't get them to be sorted how I need them to.
I have attached an example VI that shows how I'm currently implementing this function, aswell as 2 .csv files to be opened with Excel. The first file shows how the output spreadsheet file looks when you run the VI and the second file shows how I want it to look, or at least something closer to that.
To use the example VI, simply run it, select a file directory and save with any name with .csv on the end. Then open the file with Excel.
This is my first time using this forum, so if I need to provide any further information, please let me know.
Thanks for the help!
Solved! Go to Solution.
03-15-2021 11:12 AM
1. It looks like you are in a location that uses the comma as the decimal separator. This kind of makes a CSV illogical.
2. You are actually using a tab to separate your values.
So based on those, save your file as a txt instead and Excel will still open it up, using the tab as the column separators.
Additionally, you really need to watch how you are mixing arrays and strings.
I don't have the time to do a clean up of your diagram, but I would highly recommend against using the Write Spreadsheet File and just use the actual Write Text File. You can do all of the formatting of the data before that.
03-15-2021 11:23 AM
On top of what Crossrulz said I see you are also enclosing every line in quotes
I think that might also be confusing Excel and treating it as one big cell when it imports it.
I removed the quotes and used Tab as the Delimiter when importing it and it looks like this in Excel
03-15-2021 12:42 PM
Maybe something like this?
(And yes, save it as *.txt, the open it in excel. Since you only have integers, you can change the delimiter for all "array to spreasheet string" function to comma and name the file *.csv, but be aware that if your localization also uses comma as decimal delimiter for numerics, you need to change a few things)
As others have said, you really need to familiarize yourself with format codes and datatypes. "%s" is not a format for numeric arrays and if you have integers, you should not have anything orange. I would also recommend to get away from formula nodes. You are just overcomplicating things here. Use array diagram constants instead of all these loose scalars!
03-22-2021 08:29 PM
Thank you for the advices and solutions.