Excel.NamedItemCollection class
ブックまたはワークシートの一部であるすべての NamedItem オブジェクトのコレクション (到達方法に応じて異なります)。
- Extends
プロパティ
| context | オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。 |
| items | このコレクション内に読み込まれた子アイテムを取得します。 |
メソッド
| add(name, reference, comment) | 指定のスコープのコレクションに新しい名前を追加します。 |
| add |
ユーザーのロケールを数式に使用して、指定のスコープのコレクションに新しい名前を追加します。 |
| get |
コレクションに含まれる名前付きアイテムの数を取得します。 |
| get |
名前を使用して |
| get |
名前を使用して |
| load(options) | オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
| load(property |
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
| load(property |
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
| toJSON() | API オブジェクトが |
プロパティの詳細
context
オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。
context: RequestContext;
プロパティ値
items
メソッドの詳細
add(name, reference, comment)
指定のスコープのコレクションに新しい名前を追加します。
add(name: string, reference: Range | string, comment?: string): Excel.NamedItem;
パラメーター
- name
-
string
名前付きの項目の名前。
- reference
-
Excel.Range | string
名前が参照する数式または範囲。
- comment
-
string
省略可能。 名前付きアイテムに関連付けられているコメント。
返品
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/34-named-item/create-and-remove-named-item.yaml
await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getItem("Sample");
const headerRange = sheet.getRange("A1:D1");
sheet.names.add("ExpensesHeader", headerRange);
const namedItems = sheet.names.load("name, type");
await context.sync();
});
addFormulaLocal(name, formula, comment)
ユーザーのロケールを数式に使用して、指定のスコープのコレクションに新しい名前を追加します。
addFormulaLocal(name: string, formula: string, comment?: string): Excel.NamedItem;
パラメーター
- name
-
string
名前付きの項目の名前。
- formula
-
string
名前が参照するユーザーのロケールの数式。
- comment
-
string
省略可能。 名前付きアイテムに関連付けられているコメント。
返品
注釈
getCount()
コレクションに含まれる名前付きアイテムの数を取得します。
getCount(): OfficeExtension.ClientResult<number>;
返品
OfficeExtension.ClientResult<number>
注釈
getItem(name)
名前を使用して NamedItem オブジェクトを取得します。
getItem(name: string): Excel.NamedItem;
パラメーター
- name
-
string
名前付き項目名。
返品
注釈
例
await Excel.run(async (context) => {
const sheetName = 'Sheet1';
const nameditem = context.workbook.names.getItem(sheetName);
nameditem.load('type');
await context.sync();
console.log(nameditem.type);
});
getItemOrNullObject(name)
名前を使用して NamedItem オブジェクトを取得します。 オブジェクトが存在しない場合、このメソッドは isNullObject プロパティが true に設定されたオブジェクトを返します。 詳細については、「 *OrNullObject のメソッドとプロパティ」を参照してください。
getItemOrNullObject(name: string): Excel.NamedItem;
パラメーター
- name
-
string
名前付き項目名。
返品
注釈
load(options)
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。
load(options?: Excel.Interfaces.NamedItemCollectionLoadOptions & Excel.Interfaces.CollectionLoadOptions): Excel.NamedItemCollection;
パラメーター
読み込むオブジェクトのプロパティのオプションを指定します。
返品
load(propertyNames)
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。
load(propertyNames?: string | string[]): Excel.NamedItemCollection;
パラメーター
- propertyNames
-
string | string[]
読み込むプロパティを指定するコンマ区切りの文字列または文字列の配列。
返品
例
await Excel.run(async (context) => {
const nameditems = context.workbook.names;
nameditems.load('items');
await context.sync();
for (let i = 0; i < nameditems.items.length; i++) {
console.log(nameditems.items[i].name);
}
});
load(propertyNamesAndPaths)
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。
load(propertyNamesAndPaths?: OfficeExtension.LoadOption): Excel.NamedItemCollection;
パラメーター
- propertyNamesAndPaths
- OfficeExtension.LoadOption
propertyNamesAndPaths.select は読み込むプロパティを指定するコンマ区切りの文字列であり、 propertyNamesAndPaths.expand は読み込むナビゲーションのプロパティを指定するコンマ区切りの文字列です。
返品
toJSON()
API オブジェクトが JSON.stringify() に渡されるときに、より有用な出力を提供するために、JavaScript toJSON() メソッドをオーバーライドします。 (次に、JSON.stringify渡されたオブジェクトの toJSON メソッドを呼び出します)。元の Excel.NamedItemCollection オブジェクトが API オブジェクトであるのに対し、 toJSON メソッドは、コレクションの項目から読み込まれたプロパティの浅いコピーを含む "items" 配列を含むプレーンな JavaScript オブジェクト ( Excel.Interfaces.NamedItemCollectionData として型指定された) を返します。
toJSON(): Excel.Interfaces.NamedItemCollectionData;