LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to generate the .xls file which can be stored as .csv file?

Dear All,
 
         I want to generate a .csv file, but with the tab operated values.
 
         Currently I am generating the csv file with the csv option, but the data of the 16 channels, dont be the tab seperated and it stores all the 16-channel's data in single cell.
 
         Instead i want to generate a csv file, which can be tab seperated and it should store 16-channel's data in 16 continuous cell in a single row, and it must be the .csv file.
 
         This process is of course posiible to store the 16 channel's data into 16 continuous cell of row, but that file will be stored as .xls file, but customer requires the .csv file, so that it can read the csv file directly into their software.
 
I have attached my vi and the csv file which is generated by the vi.
 
          Extract the Data1.csv file and you will get the Data1.csv which is the file i am getting from the vi, and data2.xls is the file with the format which i want in the csv file.
 
Thanks in Advance,
Nishant

Message Edited by Nishant on 02-23-2007 05:39 AM

Message Edited by Nishant on 02-23-2007 05:41 AM

Download All
0 Kudos
Message 1 of 10
(6,961 Views)
Hi Nishant,
csv means comma separated value, but the comma can also be a semicolon or a tabulator. Your xls- file is also a csv- file with tabs as separators. If you want Excel to open csv files (with ending *.csv) in the correct way, you need to separate the values by commas. And if this also OK, when the data is all in one cell, you can select the cell and chose "Data in Columns" (might be something different since I have only german Excel) from the Data menu.
You had a hard time building the string with all the tabs. The easy way is to use Array to Spreadsheet string, which even converts the dbl to string. And there you can define the separator character.
Greets, Dave

Message Edited by daveTW on 02-23-2007 01:45 PM

Message Edited by daveTW on 02-23-2007 01:52 PM

Greets, Dave
0 Kudos
Message 2 of 10
(6,952 Views)
Hiii,

            Thanks for the prompt reply first of all, as you told that if all the datas are in the same cell then i can select the cell and then parse it into the column, but as we are giving this to customer,we can't rely on customer to change this and even this csv file will be read by the scada right after the data will be stored by LabVIEW, so there is no procedure to do it manually.

           I will check, if there could be any option in the LabVIEW itself to do the parsing by tab seperated.

           As you can see I have added tab constant after each n every string, which was not possible with the option of Array to Spreadsheet string, thats why I have done this way, anyways thanks for the reply.

Thanks,
Nishant
0 Kudos
Message 3 of 10
(6,937 Views)
Hi nishant,

of course it's possible to use 'Array to spreadsheet string'! There's a 'delimiter' input with a default value of "tab" already! Just change this value to whatever you need.

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 10
(6,930 Views)

You've made an extremely easy task much more difficult. If you create a file with the .csv extension, then you should actually use a comma as a separator instead of a tab. Excel assumes a comma when reading a .csv file. In the frame where you do the array indexing, number to string, concantanate to string - all can be replaced with TWO functions. You can wire an array of numerics into a single Number to Fractional String and then wire the output to an Array to Spreadsheet String function. Replace that mess you have with the code below and you will have an actual csv file that Excel will read correctly and each value will be put into its own cell.

You've got some other things in your program that don't make much sense either. Like the two stop buttons where one is wired to the LabVIEW Stop function and I don't understand why you are converting the process values to dbl when the data you are reading is I32. Also, since you have 7.1 and are using VISA, get rid of the old serial compatability functions (which use VISA anyway) and maybe add some error checking.

Message Edited by Dennis Knutson on 02-23-2007 07:51 AM

Message 5 of 10
(6,928 Views)
Hiii Gred,

             Thats a really good idea, that wasn't in my mind at al... great idea... i will try it and I am sure it will work and i also think that it will store the data with tab delimited in the csv file. what you say? am I right?

Thanks,
Nishant
0 Kudos
Message 6 of 10
(6,923 Views)
Hiii Dennis,

               I think you are right on this... I have done some fullish code...i will replace it and i think that will work, the point of converting data into double is also right, there is no sense to do this as it can work with the I32 type, so that memory can be decreased.

              Actually I have got this vi of Modbus from the forum, so in visa i dont have much idea but still i will check it out, you are great man.... thanks very much.

Thanks,
Nishant
0 Kudos
Message 7 of 10
(6,910 Views)

Hiii Dennis,

             It works even without using the number to fractional string, thanks very much.

Thanks,

Nishant

0 Kudos
Message 8 of 10
(6,876 Views)
You're right. The Array to Spreadsheet function does it all.
0 Kudos
Message 9 of 10
(6,867 Views)

In addition to what Dennis mentioned, there are quite a few other mistakes in your program, for example:

  1. You open the file outside the loop and then continue to write inside frame #2 of the stacked sequence and close (!) the file after the case structure (still inside the while loop). This means that at the second iteration the writing will fail. Your code wil never know, because you don't use the error information for anything useful. Solution: Place the "close file" outside the while loop on the right and wire the file reference and error cluster across in ALL cases. Never use any default output tunnels for file references! Stop the loop if an error occurs. (As Dennis already mentioned, get rid of "STOP" and the STOP node!! Stop your VI with the "Stop 2" button).
  2. You don't need any of the sequence structures because dataflow fully determines execution order once you use VISA. Simply use the error cluster to properly sequence the serial operations. Everything else already has data dependency.
  3. You might want to skip writing to the file in all the cases where the array is empty.
  4. When you initilize arrays with diagram constants it would make more sense to do that once outside the big loop and not with every iterations (sure the compiler might fold the code anyway, but still....).
  5. Be aware that .csv is not necessarly a good choice of you ever plan to use your code in certain european countries that use the comma as a decimal seperator.
  6. That small while loop in case 15 of one of the small case structures does a very simple operation way too convoluted. You could e.g. reshape to a Nx8 2D array and use an autoindexing FOR loop. ( no more splitting arrays, shift registers, comparison operations, etc.)
  7. ...

Good luck! 🙂

Message 10 of 10
(6,861 Views)