excelClose

Version 24.1.8896


excelClose


关闭由 excelOpen 创建的可读 Excel 句柄。

可选的参数

  • handle: 对 Excel 工作簿数据的可读句柄引用。

输出属性

  • success: 如果句柄成功关闭,则该属性的值为“true”。 如果句柄没有成功关闭,则该属性不存在。

示例

此示例打开磁盘上的现有 Excel 工作簿,使用 excelGet 操作从特定单元格读取数据,关闭 Excel 工作簿,并将该数据作为新的输出文件推送。

<!-- 创建操作的输入项并将其传入 -->
<arc:set attr="excel.file" value="C:\Temp\movies.xlsx" />
<arc:call op="excelOpen" in="excel" out="result" >
  <!-- 解析 excelOpen 中的句柄以在 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" />
  <!-- 在excelOpen内部调用excelGet来使用句柄-->
  <arc:call op="excelGet" in="get" out="out">
    <!-- 根据从 Excel 工作表读取的数据创建一些输出数据和文件 -->
    <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" />
    <!-- 使用 arc:finally 关键字最后执行句柄的关闭 -->
    <arc:finally>
      <!-- 使用 arc:finally 关键字最后执行句柄的关闭 -->
      <arc:call op="excelClose" in="excel" out="close">
        <!-- 检查以确保句柄已关闭,如果未关闭则抛出错误 -->
        <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>
<!-- 将输出项作为文件推送出去 -->
<arc:push item="output" />