Writing LabVIEW Data to an Existing Excel File

Updated Jun 13, 2018

Reported In

Software

  • LabVIEW Report Generation Toolkit

Issue Details

  • I have an existing Excel file and I would like and add data to it
  • I would like to add data to the beginning, middle, or end of an Excel file without deleting old data
  • I would like to write to an Excel file each iteration of a loop instead of building the whole report and then writing to file

Solution

To append to the beginning or middle of an Excel file:

  1. Configure LabVIEW to open an existing Excel file by using the New Report VI with Excel as the report type and the file path of your Excel file as the template. This will open your existing Excel file and any subsequent Report VIs will modify the existing file.
  2. To insert data at the beginning or middle of your file you need to first add new space in which to place the data. Use Excel Insert Cells VI to add new cells, rows, or columns to your Excel file depending upon the amount of data you will add. Select where the new cells will be placed and then use other Report VIs to insert your data into this space.
  3. Use the same start values used for the Excel Insert Cell VI for the start position input terminal of the VI you will use to insert the data. For example, if you used the Excel Easy Table VI, you would wire your desired start values to the Start (0,0) terminal.

 

To append to the End of an Excel file:

  1. Configure LabVIEW to open an existing Excel file by using the New Report VI with Excel as the report type and the file path of your Excel file as the template. This will open your existing Excel file and any subsequent Report VIs will modify the existing file.
  2. You can programmatically append data to your existing Excel file by first using the Excel Get Last Row VI to get the position of the last row and column in the Excel file. This VI will return a cluster that includes the position of the last row and column.
  3. Use an Unbundle By Name function to extract the Position of the last row and column from this cluster.
  4. Use this Position as the input start position for the VI you will use to insert the data.  For example, if you used the Excel Easy Table VI you would wire this Position to the Start (0,0) terminal.

To write to an Excel file each iteration of a loop: 

  1. Check if the file already exists using the Check if File or Folder Exists VI. Use a Case Structure to handle each situation.
  2. If it doesn't exist, such as in the first iteration of a loop, use the Save Report to File VI as seen in the image below.


Additional Information

You can also add additional functionality such as password protection by wiring in the Save Report to File to the New Report.vi.
 

WAS THIS ARTICLE HELPFUL?

Not Helpful