Example Code

Appending Spreadsheets to New Columns

Code and Documents

Attachment

Overview

When logging data in your applications sometimes the default behaviour of appending files does not do exactly what you would expect. By default when writing to a spreadsheet in LabVIEW you can append to the bottom row of the file and end up having a file that's tall in height but small in width. However, it's possible that in some cases this will not be satisfactory and you will want to log your application in chunks of samples stacked together column next to column. This example does exactly that with 2D Array manipulations.

 

Description

The program generates two random numbers (which in your application could for instance be time and a corresponding reading). These two values are then "bundled" into a column of data for one sample. Then this is repeated continuously and new samples are stacked horizontally (rather than vertically). After that we check whether file path control is empty and if so, it creates a file. But if the file already exists the program then appends to the it in horizontal axis. Please be aware that if column number is different that his will not work and cause faulty behaviour, but feel free to implement additional functionality to check for that and act accordingly if you're interested in improving this example.

  

Steps to Implement or Execute Code

  1. Open the example VI.
  2. Select an empty .xls file in File Path Control or run it with an empty one.
  3. Select a file to save to if none was specified in the previous step.
  4. Run the example VI several times.
  5. Open the .xls file and observe how columns were appended to the right of the .xls file rather than the bottom.

 

Requirements

LabVIEW 2012 or later

 

Additional Images or Video

 

ss.png

 **This document has been updated to meet the current required format for the NI Code Exchange.**

 

______________________________________________________

Mark N
Applications Engineer
National Instruments UK & Ireland

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