Example Code

Continuously Write to an Excel Spreadsheet using LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview

This example generates random numbers then compares them to a limit and writes the numbers in a tab delimited file

 

Description

This VI uses the random number generator to get a number every second between 0 and 100. It then compares that number to a user defined "limit."  When the value is greater than the limit, a boolean on the front panel lights up. Every time the loop iterates, it writes the values to a spreadsheet selected by the user. It will give the iteration, date, time, value, and whether it is under or over the threshold.

The VI writes header information to a specified file, separates each column by a tab character, and finishes the string with an end of line character to signal the end of the row.  Inside the while loop it acquires a random number, compares the number to a user-defined limit, displays the number on a chart, and formats and writes the data to a file.  The VI will then close the file and check for errors outside of the loop. The information is stored in a file using a tab-delimited format, not .xls or .xlsx, and can be used to create human-readable text files. The file that is saved can be opened in Microsoft Excel with the proper column separation.

  

Requirements: LabVIEW Full Development System 2012 or compatible

 

Steps to Implement or Execute Code

  1. Make sure the Power toggle switch is ON.
  2. Run the VI
  3. Set a Limit that the file will identify whether the random number is over or under that value
  4. Specify a name and location for the spreadsheet file in the file dialog box that appears.
  5. Flip the Power toggle switch to OFF to stop the VI.

 Additional Information or References

VI Code Screenshot

 Capture.PNG

 

**The code for this example has been edited to meet the new Community Example Style Guidelines.**

Chris Van Horn
Applications Engineer

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
eng.3zam
Member
Member
on

Nice document

i wante it

thanks

Liangnimalegebi
Member
Member
on

When using mac amd MS office for OS, the spreadsheet file extension should be xls.  If using .xlsx, there will be error.

alvin.zhuo
Member
Member
on

A new thought for creating customized file.thanks