Share via


Ewa.NamedItemCollection.getItemByName(name)

**適用対象:**apps for SharePoint | Excel Services | SharePoint Server 2013

この記事の内容
戻り値
注釈

対象

一致する名前と名前付きアイテムを取得します。

var value = Ewa.NamedItemCollection.getItemByName(name);

パラメーター

name

戻り値

名前付きアイテム

注釈

getItemByNameメソッドは、インデックスの値として、名前付きアイテムの表示名を使用して、指定した名前付きアイテムを返します。複数の名前付きアイテムは、同じ名前を付ける場合は、下のインデックスの値を持つ名前付きアイテムを返します。名前付きアイテムが存在しない場合は、null を返します。

コードの例を次のページにボタンとテキストの入力] ボックスを追加する方法について説明テキスト ボックスに入力された名前付きアイテムの名前をボタンonClickイベントにイベント ハンドラーを追加し、同じ名前の名前付きアイテムを取得します。イベント ハンドラーでは、警告メッセージで、名前付きアイテムのNamedItemTypeが表示されます。コードの例では、 Excel Web Access Web パーツでSharePoint Server 2013で作業していることを前提としています。

<script type="text/javascript">
 
var ewa = null;
 
// Add event handler for onload event.
if (window.attachEvent) 
{ 
    window.attachEvent("onload", ewaOnPageLoad);    
} 
else 
{ 
    window.addEventListener("DOMContentLoaded", ewaOnPageLoad, false); 
}

// Add event handler for applicationReady event.
function ewaOnPageLoad() 
{ 
Ewa.EwaControl.add_applicationReady(getEwa); 
} 

function getEwa()
{        
    // Get a reference to the Excel Services Web Part.
    ewa = Ewa.EwaControl.getInstances().getItem(0);                                   
}              

// Get NamedItemType as string.
function getNamedItemTypeAsString(type)
{
    var myType = null;
    
    switch(type)
    {
        case Ewa.NamedItemType.NamedRange:
            myType = "NamedRange";
            break;
        case Ewa.NamedItemType.Parameter:
            myType = "Parameter";
            break;
        case Ewa.NamedItemType.Table:
            myType = "Table";
            break;
        case Ewa.NamedItemType.PivotTable:
            myType = "PivotTable";
            break;
        case Ewa.NamedItemType.Chart:  
            myType = "Chart";
            break;
        default:
            myType = "undefined";
    }        
    
    return myType;    
}


// Use the button onClick event handler.
function getTypeButton()
{
    // Get the name of the named item from the text box.
var niName = document.getElementById("EnterName").value; 

// Get the NamedItems collection.
    var items = ewa.getActiveWorkbook().getNamedItems();
    
    // Get the specified named item in the collection by friendly name.
var item = items.getItemByName(niName);

 
if (item != null) 
{
    // Get the NamedItemType as a string.
        var type = getNamedItemTypeAsString(item.getNamedItemType());        
        alert("Named item " + niName + " has a named item type of " + type + ".");              
}
else
{
// No named item present with that friendly name.
alert("No named item by that name.");
    }
}

</script>
<input type="text" id="EnterName" value="Enter name" />
<input type="button" id="GetNiType" value="Get Named Item Type" onclick="getTypeButton()" />

対象

Ewa.NamedItemCollection オブジェクト

関連項目

概念

Ewa.NamedItemCollection 方法

Ewa 名前空間