From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Example Code

Write Multiple Columns With Write to Spreadsheet File VI

Code and Documents

Attachment

Download All

Overview

This example demonstrates how to log multiple columns of data into a spreadsheet file (comma delimited, tab delimited, etc.) with the Write to Spreadsheet File VI

Description

The Write to Spreadsheet File VI takes data in the form of 1D or 2D arrays. To have the data in the arrays show up as columns, we can transpose the array. Each element in the array will contain multiple data values, one for each column. The data values will be separated by commas or tabs, depending on the file type. This example demonstrates inserting three columns of data into a CSV file.

Steps to Implement or Execute Code

  1. Create column labels by creating a String array and putting the column labels into the first element of the array. Write this array into a spreadsheet file with the Write to Spreadsheet File VI. Set the Transpose value to True.

  2. Convert data for each column into Strings and append them. Delimit each data value with a comma (for CSV files) or tabs (for tab-delimited files). If using a loop where one set of data is acquired in each iteration of the loop, only one appended string is needed. Otherwise, several appended strings will be needed.

  3. Insert the appended string(s) into a 1D String array.

  4. Write the 1D String array into the spreadsheet with the Write to Spreadsheet File VI. Set the Append and Transpose values to True.

Requirements

Software

LabVIEW

Additional Images or Video


Snippet:

snippet.png

Sample spreadsheet created with this VI:

sample csv.PNG

Humphrey H.
Applications Engineer
National Instruments

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

Comments
mesutozil
Member
Member
on

hi..by using this code,is it able to save the data in different file?..

gauraangKhurana
Member
Member
on

I have 10 arrays of 20000 values each. Your code is taking alot of time. IT IS VERY SLOW.

crossrulz
Knight of NI Knight of NI
Knight of NI
on

Generally speaking, the Write Delimited Text File (or Write To Spreadsheet File) should not be used inside of a loop.  That VI opens the file, sets the file pointer, writes the data, and closes the file each time it is called.  This is extremely expensive.  The file should be opened/created before the loop, closed after the loop, and then you can write as much as you need inside of the loop.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
RobertoBozzolo
Proven Zealot
Proven Zealot
on

Hello, for some reason this example have been tagged with the CVI keyword which as evident has nothing to do with it. Can you remove the CVI tag from it?



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Contributors