excelOpen

Version 23.4.8839


excelOpen


Creates a readable handle for an existing Excel workbook.

Required Parameters

  • file: The full path on disk, including the filename, of the Excel workbook.

Optional Parameters

  • version: The Excel version of the target workbook. The allowed values are AUTO, 95, 97-2003, 2007. The default is AUTO.

Output Attributes

  • handle: A readable handle reference to the Excel data. This handle can be used by subsequent operations, as shown in the following example.

Example

This example opens an existing Excel workbook on disk, reads data from specific cells using the excelGet operation, closes the Excel workbook, and pushes that data as a new output file.

<!-- Creating the input item for the operation and passing it in -->
<arc:set attr="excel.file" value="C:\Temp\movies.xlsx" />
<arc:call op="excelOpen" in="excel" out="result" >
  <!-- Resolving the handle from excelOpen to use in excelGet -->
  <arc:set attr="get.handle" value="[result.handle]" />
  <arc:set attr="get.sheet" value="film" />
  <arc:set attr="get.version" value="2007" />
  <arc:set attr="get.map:favoritemovie" value="A2" />
  <arc:set attr="get.map:favoritemovieyear" value="B2" />
  <!-- Calling excelGet inside excelOpen to use the handle -->
  <arc:call op="excelGet" in="get" out="out">
    <!-- Creating some output data and file from the data read from the excel sheet -->
    <arc:set attr="output.data" value="My favorite movie is [out.favoritemovie] and it came out in [out.favoritemovieyear]." />
    <arc:set attr="output.filename" value="results.txt" />
    <!-- Using the arc:finally keyword to execute the closing of the handle last -->
    <arc:finally>
      <!-- Calling excelClose to close the handle -->
      <arc:call op="excelClose" in="excel" out="close">
        <!-- Check to ensure the handle was closed and throw an error if it was not -->
        <arc:exists attr="close.success" >
          <arc:else>
            <arc:throw code="CloseFailed" desc="The handle was not closed successfully." />
          </arc:else>
        </arc:exists>
      </arc:call>
    </arc:finally>
  </arc:call>
</arc:call>
<!-- Push the output item out as a file -->
<arc:push item="output" />

Note: When you use excelOpen, be sure to use the excelClose operation to close the handle at the end of the script to avoid leaking memory through open handles.