04-03-2014 07:47 AM - edited 04-03-2014 07:48 AM
Afternoon all,
Got what is hopefully an easy question and a lack of brain power on my part.
I have the following code which is designed to format three strings into one final string which then gets written to file. The file is comma separated. The file has column headers named Event, Date, Time and Value.
Now, this works perfectly apart from the fact that when it comes to write the final Value column data. Because there are commas in the final format into string function, it interprets this as shift to the next cell and write rather than it being one long string with the commas shown so I end up with this:
Undesired
Instead of ending up with the desired:
Desired
So, my question is, is there a way to change this behaviour so that the final string is displayed as above?
Cheers for looking and thanks in advance.
Mitch
Solved! Go to Solution.
04-03-2014 08:10 AM
If you have a comma separated file you should not use commas within the values. Simple as that.
With date and time it is desired that they are separated into 2 columns?
I would recommend switching either the column delimiter to a semicolon (or something else) or avoid using commas within a column.
04-03-2014 08:18 AM
Hi dan_u
Problem is this is code I've inherited that I want to modify slightly and any change to the writing method will incur problems elsewhere.
Yes its desired that the date and time is separate and I actually prefer it that way to be honest.
Switching to an alternative delimiter may end up being the only way to achieve what I want but I just wanted to know 100% that there is no special method to allow the commas to be shown like the special escape codes.
04-03-2014 08:26 AM
Mitch,
escaping the comma could be an option but that would depend on the application accessing the csv file. I'm not aware of a general way.
04-03-2014 08:28 AM
You have left out the code that you use to write to the file and this will influence the result you get
When I want to do this I create an array of the data (1 item per column) and use Write to spreadsheet file.vi to get a tab delimited file which can then be opened in Excel using text to columns
Ken
04-03-2014 08:28 AM
Write to spreadsheet file does have the Delimiter optional input (Default tab). What are you using to write to file?
04-03-2014 08:44 AM - edited 04-03-2014 08:47 AM
Hey Mitch_Peplow,
This will solve your issue. The " " marks wont be displayed while viewing in excel. In case if this data is used for something else in labVIEW, you can just use the replace string function and replace " " with empty strings as there are no other " " used in the string.
Regards,
Nitzz
(Give Kudos To Good Answers, Mark it as a Solution If your Problem was Solved )
04-03-2014 08:45 AM
LabVIEW both reads and writes to the file and apart from that we only open it in Microsoft Excel.
I left out the rest of the code as there is more processing going off before we write, I wanted to keep it simple.
The code is currenty using the Write to Text File.
04-03-2014 09:08 AM
@Mitch_Peplow wrote:
LabVIEW both reads and writes to the file and apart from that we only open it in Microsoft Excel.
The code is currenty using the Write to Text File.
Then the fix is easy- use write to spreadsheet to format the darn text into a spreadsheet that you only open in excel and read from spreadsheet to read the spreadsheet
04-03-2014 09:08 AM
Pure and simple, if you have a comma separated values, you can't have commas in the data. I would recommend changing the last string to use a tab instead of a comma. A semicolon would be my second choice. But why not just have 2 additional columns? That would be the easiest.