Changing the Value of a Cell in an Existing Microsoft Excel Spreadsheet Using LabVIEW

Updated Jul 11, 2023

Environment

Software

  • LabVIEW

I have a problem opening an existing Excel worksheet and programmatically changing the value of a cell using LabVIEW. What steps should I follow?

When communicating with Microsoft Excel using LabVIEW, you have two primary methods:
 
 The first method is to create a VI, in which you must open an ActiveX reference to the spreadsheet file and then the sheet and finally the cell or range of cells that you want to edit.   
This can be done by using ActiveX controls with property and invoke nodes to programatically change values and styles in Excel going either cell by cell or by changing a range of values.
  1. Open Excel programatically with an ActiveX Property Node that is linked into a "Workbooks" ActiveX Invoke Node (For this example, we send the path file from a control on the front panel)
  2. Open the specific sheet within the Excel file using the name of the sheet
  3.  Make a Worksheet Invoke Node and use the refnum constant from that Invoke Node to select your sheet
  4.  Find a range in that sheet to edit by using the Range property in the Worksheet Invoke Node
  5. Use the range refnum to edit the full range you selected or send in coordinates and the new values all over the worksheet
  6.  Close all open references



The other method available for use in manipulating Microsoft Excel from LabVIEW is the Report Generation Toolkit for Microsoft Office. The VIs and examples included with this toolkit streamline LabVIEW's communication with Microsoft Excel and Word.

Additional Information

Microsoft Word and Microsoft Excel are powerful standard software packages for creating reports. Because of their popularity, some LabVIEW users programmed LabVIEW ActiveX applications to dynamically control these document packages for generating reports from LabVIEW. The complexity of the ActiveX interface of those packages, however, makes the development of custom applications difficult. With the LabVIEW Report Generation Toolkit, which is included with LabVIEW Professional 2014 and later, you no longer have to learn the complex object models of Microsoft Word and Excel to generate a report. The Report Generation Toolkit is a library of flexible, easy-to-use VIs for programmatically creating and editing Microsoft Word and Excel reports from LabVIEW.