> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kasoftware.com/llms.txt
> Use this file to discover all available pages before exploring further.

# excelOpen

> 開啟 Excel 工作簿並傳回可供其他 Excel 操作使用的控制代碼。

為現有 Excel 工作簿建立可讀控制代碼。

## 必需的參數

* **file**: Excel 工作簿在磁碟上的完整路徑，包括檔名。

## 可選的參數

* **version**: 目標工作簿的 Excel 版本。 允許的值為`AUTO`、`95`、`97-2003`、`2007`。 預設為`自动`。

## 輸出屬性

* **handle**: 對 Excel 資料的可讀控制代碼引用。 該控制代碼可供後續操作使用，如下例所示。

## 範例

此範例開啟磁碟上的現有 Excel 工作簿，使用 [excelGet](./op-excel-get) 操作從特定單元格讀取資料，關閉 Excel 工作簿，並將該資料作為新的輸出檔案推送。

```xml theme={null}
<!-- 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>當使用excelOpen時，請務必在指令碼末尾使用[excelClose](./op-excel-close)操作關閉控制代碼，以避免透過開啟的控制代碼洩漏記憶體。</Note>
