LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing continuously to excel

Solved!
Go to solution

Hi,

Ive asked a similar question before but now I understand the parameters a bit better.

My array writes to a waveform chart and at the end exports the graph to excel. However, i need it to continuously write the data to an excel file for the safety of the data. Is write to delimited spreadsheet the correct thing to use?

Thanks

0 Kudos
Message 1 of 18
(6,462 Views)

Hello, Newman,

 

you can use the write to delimited spreadsheet.vi with the append to file? input set to true. This will not give you a 'real' excel file, but only a tabular text file that excel can read and convert. None of the formatting options of excel are available here.

 

Depending on how big your data set is, you might want to consider storing it in a binary format (e.g. tdms) and generate an excel report at the end. Your suggestion will do what you asked for, though.



Remember Cunningham's Law
0 Kudos
Message 2 of 18
(6,436 Views)

A couple of points. 

  • "Excel" is a Microsoft program that uses a proprietary data format (.xls, .xlsx) to create Workbooks that hold Worksheets that resemble "spreadsheets" used by bookkeepers in Times Gone Bye. 
  • One can create a "Spreadsheet file" by writing a text file where numeric values are written as strings, with rows written as separate lines of text, and columns separated by a specific character, such as a comma (in which case the file is called a "Comma-Separated Values", or .csv, file) or a horizontal tab.
  • If you have Microsoft Office installed on your PC, it creates an "Excel-like" Icon for .csv files (which implies, correctly, that if you double-click them, they will open in Excel and "look like" they were created by Excel, even though they probably were not).
  • If you use LabVIEW to write a "Spreadsheet File" or a "Delimited Spreadsheet", the LabVIEW defaults are to write a tab-separated file, and give it the .csv (comma-separated) extension.

Now that I've gotten that out of the way, your question comes down to wanting to save data "as it is acquired".  There are plenty of discussions of how to save data being acquired that involve such questions as "how fast are the data arriving", "how many channels of data", "are all of the data numeric?", "how much precision do you need", "do you need any meta-data, such as sampling rates, time of day, operator name, etc".

 

Continuous data acquisition usually involves opening the output file first, and doing the "continuous acquisition and storage" in one or more While Loops, with the file reference wire held in a Shift Register.  In many cases where time is critical (i.e. high data rates), a Producer/Consumer design lets data saving happen pseudo-simultaneously with data acquisition.

 

I looked at your VI.  You seem to be using proprietary third-party acquisition code.  I recommend you take a look at some LabVIEW DAQmx examples to see how DAQ code should be written.  Usually Acquisition Functions are "self-clocking" -- you say "Acquire 1000 samples at 1 kHz", put this in a loop, and that loop will run exactly at 1 Hz (as it takes 1000 * (1/1000) seconds to do the acquisition).  It is (almost always) a mistake to put any other timing function in a DAQ loop.

 

Bob Schor

Message 3 of 18
(6,426 Views)

Thanks that worked but the delimiter doesnt seem to work? tried a few combinations of (\t)

labview.PNG

lab excel.PNG

0 Kudos
Message 4 of 18
(6,410 Views)

Have you tried terminal's default value? You can try creating the default value constant via right-click menu(Create >> Constant). Then you'll see '\t' under the string's code display mode.

Tab Delimiter.png

 

-Tianbin

Message 5 of 18
(6,403 Views)

Hi, Ive tried that but now i just get this instead? the file is a csv if that makes any difference

Thanks

 

lbview.PNGexcel.PNG

0 Kudos
Message 6 of 18
(6,369 Views)
Solution
Accepted by topic author newman3108

Exactly, the .csv file is the difference.  For .csv file, you should just use comma(',') instead of '\t' as delimiter.  I tried that the '\t' delimiter works well for .xlsx and .xls file formats.

 

Regards,

Tianbin

Message 7 of 18
(6,365 Views)

Yeah that was pretty stupid, wasnt aware you could do xls files.

Thanks for your help 

0 Kudos
Message 8 of 18
(6,360 Views)

@newman3108 wrote:

Yeah that was pretty stupid, wasnt aware you could do xls files. 


I'm not sure what you mean by "could do xls files".  Write Delimited Spreadsheet (formerly named, I think, "Write Spreadsheet File") writes a plain Text File, using a character (LabVIEW default is <tab>) between entries of a 1D Array, and for 2D arrays, writes each row as a line of text, separating rows with <CR><LF>.  This particular format of text files, useful to display tabular numeric data, is (particularly when a comma is used as a delimiter) called a "Comma-Separated Values" (or .CSV) file.  

 

Microsoft's Excel program can read text files of this format, and, indeed, has created an "Excel-like" Icon for files with the .csv extension (which fools people into thinking these are "Excel Files").  Microsoft can, indeed, read these and bring them into Excel, where they can be manipulated, but if you try to save them, you'll get a warning that "certain features" won't be saved in the (ordinary) Text file, and are invited to save the file in Excel's proprietary .xlsx format.

 

If you read the Help for Write Delimited Spreadsheet, you'll see a disclaimer that this is, indeed, a pure Text file, and if you want to use Excel's "native" file format, you need to use ActiveX or the Report Generation Toolkit.  The Help also notes that LabVIEW uses the <tab> as the default separator, not the comma.

 

Bob Schor

Message 9 of 18
(6,350 Views)

I have a similar problem on LabVIEW NXG.

I'm trying to write data in a .csv file in a slow (1s) loop so that one line is written at each iteration

I use the "write in a spreadsheet file" node with "append to file" checked

For some reason, only the last value is présent in the file

0 Kudos
Message 10 of 18
(6,321 Views)