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

# excelGet

> シート名でExcel ワークブックから値を取得します。特定のセル参照と範囲指定のセルクエリの両方に対応し、オプションでアウトプットマッピングを行えます。

Excel ワークブックから値を取得します。このオペレーションは、**Translation Mode** が**Template** に設定されている場合に、[Excel コネクタ](../../connectors/excel)のテンプレートファイルで一般的に使用されます。ただし、このオペレーションは[Script コネクタ](../../connectors/script)のような専用のスクリプトシナリオでも使用できます。

## 必要なパラメータ

* **sheet**: 値を取得するワークブック内のシート。

## オプションのパラメータ

* **version**: ターゲットワークブックのExcel バージョン。`AUTO`、`95`、`97-2003`、`2007` が使用可能です。デフォルトは`AUTO` です。
* **file**: Excel ワークブックの、ファイル名を含むディスク上のフルパス。`file` または`handle` のいずれかのパラメータを指定する必要があります。
* **handle**: [excelOpen](./op-excel-open)で作成されたExcel データへの読み取り可能なハンドルの参照。`file` パラメータを指定する場合、`handle` は不要です。
* **map:\***: 1つ以上のインプットのセット。マップされるパラメータの名前がコロンの前に置かれ（例：`map:foo`）、値はシート内のセルの名前または範囲です。たとえば、値が`C1` の`map:foo` 属性は、オペレーションの指定したアウトプットアイテムに`foo` 属性を作成し、その値はターゲットシートのセルC1 にある値になります。

  セルの範囲を指定して、範囲内のすべてのセルから値を取得することもできます。たとえば、`C1:C10` はセルC1 からC10 までのすべての値を取得します。ワイルドカード文字`*` を使用して、カラムの長さ分のセル値を取得できます。たとえば、`C1:C*` はC1 からカラムの末尾までのすべての値を取得します。

## アウトプット属性

* **\***: シートの内容と指定したクエリに依存します。カラムヘッダーがある場合、それらがアウトプット属性の名前に使用されます。さらに、インプットアイテムに`map:*` パラメータを設定した場合、アウトプットアイテムには同じ名前の属性が含まれます。追加のコンテキストについては、[例](#例)を参照してください。

## 例

追加情報とその他の例については、[Excel コネクタ](../../connectors/excel)のドキュメントの[Excel to XML](../../connectors/excel#excel-to-xml)セクションを参照してください。

### Get Values and Map to a New Item

この例では、excelGet オペレーションを使用して、指定したシートのセルとカラムから特定の値と範囲指定の値を取得し、新しいアイテムにマッピングします。新しいアイテムは、Excel コネクタのTemplate Mode の一部として、後でテンプレート内でXML アウトプットファイルの特定のXML 要素を設定するために使用できます。`arc:call` で使用される`arc:map` キーワードの詳細については、[arc:map](../keyword-reference/op-arc-map)を参照してください。

```xml theme={null}
<!-- Read the Excel -->
<arc:set attr="excel.file" value="[FilePath]" />
<arc:set attr="excel.sheet" value="Sheet1" />
<arc:set attr="excel.version" value="2007" />

<!-- Map the specific and ranged values to various attributes -->
<arc:setm item="excel">
  map:PONumber = "C5"
  map:PODate = "C6"
  map:DeliveryDate = "C7"
  map:ShipDate = "C8"
  map:BillerName = "I11"
  map:ShipperName = "C11"
  map:ShipperAddressLine1 = "C12"
  map:ShipperCity = "C13"
  map:ShipperState = "C14"
  map:ShipperZip = "C15"
  map:LineUPC = "B19:B*"
  map:LineQty = "C19:C*"
  map:LineUnit = "D19:D*"
  map:LinePrice = "E19:E*"
  map:LineDesc = "F19:F*"
  map:LineAllowanceRate = "I19:I*"
  map:LineAllowanceType = "J19:J*"
</arc:setm>

<!-- Calling the excelGet operation and using the arc:map keyword to map the output of the operation from the "result" item to a new "data" item that can be used later -->
<arc:call op="excelGet" in="excel" out="result">
  <arc:map from="result" to="data" map="*=*" />
</arc:call>
```

### excelGet in a Script Connector

この例では、[Script コネクタ](../../connectors/script)でexcelGet オペレーションを使用して、ディスク上の既存のExcel ワークブックを開き、特定のセルからデータを読み取ります。その後、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" />
```
