Create Xls File


raining010

Recommended Posts

Yes and no.  No it can't create an actual XLS file directly, though technically you could use the direct file access routines and a lot of script to do it yourself.  But: yes, you can always write to a CSV file (among other formats) which Excel will open directly.

Link to comment
Share on other sites

You can peek and poke into an existing XLS spreadsheet using the DDE driver.  It hasn't been updated in quite a while, however, so support is limited.  Extract the files to your DAQFactory folder, then rename the .dl_ one to .dll.  You also could go in reverse and enable the DDE slave and have Excel request and receive data.  That's in the existing installation.

dde.zip

Link to comment
Share on other sites

  • 2 weeks later...

Thanks Guru.

 

I've met a question, that I could write data into csv, but each time I write, it will jump to next line.

What I want is, write two data in one line, then go to next line, these three data are "VIPlot_VValues" and "VIPlot_IValues". I paste code here,

Citect provides two functions, FileWrite (write in one line), FileWriteLn (write and jump to next line), which meets my require.

 

// codes to write into csv file

 

private string VI_filename = file.FileSaveDialog(,"C:\","*.csv","Save VI data")
If(!Isempty(VI_filename))
   private VI_handle = file.Open(VI_filename+".csv",0,1,1,1) //create a csv file and get handle
   For(private.i=0,i<40,i++)
      File.Write(VI_handle,VIPlot_VValues)//V data
      File.Write(VI_handle,",")
      File.Write(VI_handle,VIPlot_IValues)//I data
   Endfor
   File.Close(VI_handle)      //close handle
Endif

the actual csv.csv

post-8996-0-29221000-1380434449_thumb.jp

the aim csv I want.csv

post-8996-0-69689500-1380434456_thumb.jp

Link to comment
Share on other sites

Hi, Guru

I did it. The working codes are, for new user's reference, and thank you all the same

 

 

private string VI_filename = file.FileSaveDialog(,"C:\","*.csv","Save VI data")
If(!Isempty(VI_filename))
   private VI_handle = file.Open(VI_filename+".csv",0,1,1,0)   //create handle
   //2nd 0, not read
   //3rd 1, write mode
   //4th 1, append mode
   //5th 1, write only one line everytime
   
   For(private.i=0,i<40,i++)
      File.Write(VI_handle,VIPlot_VValues)//V data
      File.Write(VI_handle,",")  //next column
      File.Write(VI_handle,VIPlot_IValues)//I data
      File.Write(VI_handle,chr(10))    //next row
   Endfor
   
   File.Close(VI_handle)      //close handle
Endif
Link to comment
Share on other sites

codes for csv file open dialog, read and recognize first column second column in every row, display them in text lists and XY trend

 

 

 

private string VI_filename = file.FileOpenDialog(,"C:\VI_Plot","*.csv","Select VI Plot File")

   If(!Isempty(VI_filename))

      private VI_handle = file.Open(VI_filename,1,0,0,1)   

      //the last parameter should be 1, will cause read only one line

      private string VI_line   

      //display VI curve data in list and trends

      For(private.i=0,i<40,i++)

         VI_line=file.Read(VI_handle,1)

         VIPlot_VValues=Parse(VI_line,0,",") //V data, to right list

         VIPlot_IValues=Parse(VI_line,1,",") //I data, to right list

         V.VIPlot_Trace_Y=Parse(VI_line,0,",")  //V data, to left trend

         V.VIPlot_Trace_X=Parse(VI_line,1,",")  //I data, to left trend

      Endfor

      File.Close(VI_handle)

   Endif

 

 

 

 


The opposite write code into a csv file is in above floor

Ps, I wrote these codes for a whole day!

thanks everyone

Link to comment
Share on other sites

As you discovered, DAQFactory has a parameter when you open the file which determines if it should add a CR/LF after each write() function call.  If you set the last parameter of open() to 1, then every time you do write() it will add a CR/LF.  You can use this, however, you need to do your write in one command:

 

File.Write(VI_handle,doubleToStr(VIPlot_VValues) + "," + VI_handle,VIPlot_IValues)
 
(Note I only do doubleToStr() on the first item because the second one will auto-convert to a string.  
 
That all said, if your data is any more than maybe 20 or 30 lines, you really should consider using the writeDelim() and readDelim() functions.  To use writeDelim(), you are going to have to create a 2D array of your data, but that's easy:
 
private out
out[][0] = VIPlot_VValues
out[][1] = VIPlot_IValues
file.writeDelim(VI_handle, out, ",", chr(10))
 
Reading in, you can either call readDelim() multiple times to get each column, or read the whole array and parse it out:
 
private in
in = file.readDelim(VI_handle, -1, "," chr(10), -1)
VIPlot_VValues = in[][0]   // I'm assuming VIPlot_VValues is a variable, not a channel
VIPlot_IValues = in[][1]
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.