LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading Multiple Columns from Excel Spreadsheet or CSV

I am using LabWindows/CVI 7.0.  I would like to load an Excel spreadsheet (csv if required) with 3 columns (time, v1, v2) and then proceed to write voltages to separate channels and graph data.  I want to store each of the columns in a different array.  Currently, I have this option working by loading three separate csv files with the different csv files containing time, v1, and v2 values.  I am using FiletoArray to do this.  Oviously, I can continue to load three files, but this increases the time by having to create the Excel spreadsheets and then having to load three individually.
 
I've checked the other discussion boards, and they all suggest using the "read from spreadsheet" which I only think works with LabView.
 
Any help would be greatly appreciated.
 
Thanks!
0 Kudos
Message 1 of 4
(4,304 Views)
if your data is stored as csv (text file, basically), you can just read it line by line, then scan each line for the desired values.
like so:

    if (F=fopen(DataFile, "r"))
    {
       i = 0;
        while(fgets(line, sizeof(line), F))
        {
          Scan(line, "%f,%f,%f", &time,&v1,&v2);
          Timearray[i] = time;
...
          i++;
       }
        fclose(F);
     }



--
Once the game is over, the king and the pawn go back into the same box.
0 Kudos
Message 2 of 4
(4,270 Views)

To follow up, does anyone have anything that more streamlines the interaction with Excel better than the example code?

Thanks,

Gregg

0 Kudos
Message 3 of 4
(4,092 Views)
Reading from Excel is never a very streamlined activity. The attached function will read a 2D matrix of data from a specified sheet and range in an open Excel application using the ActiveX interface. I have no idea if this helps or not, except that I do know it works.
--
Martin
Certified CVI Developer
0 Kudos
Message 4 of 4
(4,085 Views)