From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I append data to an Excel spreadsheet using ActiveX control?

I've attached a Snippet that illustrates how to use the Report Generation Toolkit functions to allow you to create and/or append data to an Excel Workbook.  Note that this writes "real Excel" (I'm using the .xlsx format, though you can also specify the .xls format by editing the file name), and doesn't (directly) require using or knowing ActiveX.

 

To run this, open LabVIEW (this snippet was made with LabVIEW 2012), and drag the .PNG file into the Block Diagram -- it should open as though it were a VI.  Save it somewhere giving it a more User-Friendly Name (I chose "Excel Append Demo.vi").  Look at the False case of the Case Statement -- this is the code that creates the Excel file "from scratch" -- it differs from the Append ("True") case as follows:

  • The New Report function does not have a path wired into the "Template" input.
  • There is no call to the Excel Get Last Row function (since we are starting at the first row)
  • The Excel Easy Table function has the Column Headers specified (since this is the first write)
  • The Start input in the Excel Easy Table function is not wired (since we are starting in the upper left hand corner)

 

This function generates 10 values at the rate of one per second (so don't panic when it seems to "stall" for 10 seconds) -- including the Timestamp in the Excel file demonstrates that the generated Excel entries come from multiple runs of the Demo.

 

Now run the Demo.  When it finishes, open the Workbook that it generates.  You should see a spreadsheet with columns labeled "Time" and "Value", and 10 data entries.  Close the Workbook, and run the code again.  Now you should see the same spreadsheet has 10 more rows appended to the original data.  The more you run it, the more data gets appended.

 

Bob Schor

0 Kudos
Message 21 of 23
(511 Views)

Oops, forgot to include the snippet ... explanation and instructions on previous post.

 

Excel Append Demo.png

0 Kudos
Message 22 of 23
(510 Views)

I have to admit I am not sure why you are getting this error. I have used this solution for years on development machines, test machines that range from desktops to laptops. I have also used the solution running Windows XP and Windows 7 on a mix of the machines mentioned before. Make sure you have the inputs correctly configured and that Excel is not open when trying to run this ActiveX solution. 

0 Kudos
Message 23 of 23
(489 Views)