OfficeRuntime.Storage interface

非同期、グローバル、永続キー値ストレージ。

注釈

API セット: SharedRuntime 1.1、Mailbox 1.10

このインターフェイスは、Excel、PowerPoint、および Word アドインの SharedRuntime 1.1 要件セットで使用できます。Outlook のメールボックス要件セット 1.10 以降でも使用できます。

重要: Outlook では、サポートは Outlook on Windows に実装されている イベント ベースのライセンス認証 機能でのみ利用できます。 このインターフェイスは、Outlook on Mac または Outlook on the web ではサポートされていません。

ストレージの制限はドメインあたり 10 MB で、複数のアドインで共有できます。

メソッド

getItem(key)

キーに基づいてストレージから項目を取得します。 Promise を返します。 Promise が解決されない場合は、null を返します。

getItems(keys)

キーに基づいてストレージから複数の項目を取得します。 Promise を返します。 Promise が解決されない場合は、null を返します。

getKeys()

ストレージからすべてのキーの配列を取得します。 Promise を返します。

removeItem(key)

アイテムをキーに基づいてストレージから削除します。 Promise を返します。

removeItems(keys)

ストレージから複数のアイテムを削除します。 Promise を返します。

setItem(key, value)

キーと値のペアをストレージに設定するか、既存のキーと値のペアを更新します。 Promise を返します。

setItems(keyValues)

複数のアイテムをストレージに設定するか、ストレージ内の複数のアイテムを更新します。 Promise を返します。

メソッドの詳細

getItem(key)

キーに基づいてストレージから項目を取得します。 Promise を返します。 Promise が解決されない場合は、null を返します。

getItem(key: string): Promise<string | null>;

パラメーター

key

string

取得する項目のキー。 文字列でなければなりません。

返品

Promise<string | null>

注釈

API セット: SharedRuntime 1.1、Mailbox 1.10

このメソッドは、Excel、PowerPoint、および Word アドインの SharedRuntime 1.1 要件セットで使用できます。Outlook のメールボックス要件セット 1.10 以降でも使用できます。

重要: Outlook では、サポートは Outlook on Windows に実装されている イベント ベースのライセンス認証 機能でのみ利用できます。 この方法は、Outlook on Mac または Outlook on the web ではサポートされていません。

// Retrieve a value from the shared runtime storage by its key.
async function getItem() {
    const key = document.getElementById('readKey').value.trim();

    const value = await OfficeRuntime.storage.getItem(key);

    if (value === null) {
        console.log(`Item not found - Key "${key}" not found in storage.`);
    } else {
        console.log(`Item retrieved successfully - Key: "${key}"\nValue: "${value}"`);
    }
}

getItems(keys)

キーに基づいてストレージから複数の項目を取得します。 Promise を返します。 Promise が解決されない場合は、null を返します。

getItems(keys: string[]): Promise<{ [key: string]: string | null }>;

パラメーター

keys

string[]

削除するアイテムのキー。 文字列の配列でなければなりません。

返品

Promise<{ [key: string]: string | null }>

注釈

API セット: SharedRuntime 1.1、Mailbox 1.10

このメソッドは、Excel、PowerPoint、および Word アドインの SharedRuntime 1.1 要件セットで使用できます。Outlook のメールボックス要件セット 1.10 以降でも使用できます。

重要: Outlook では、サポートは Outlook on Windows に実装されている イベント ベースのライセンス認証 機能でのみ利用できます。 この方法は、Outlook on Mac または Outlook on the web ではサポートされていません。

// Retrieve a set of default values from the shared runtime storage.
async function getDefaultSettings() {
  const keysToRetrieve = [
      'username',
      'email',
      'theme',
      'lastLogin',
      'preferences'
  ];

  const items = await OfficeRuntime.storage.getItems(keysToRetrieve);
  for (const [key, value] of Object.entries(items)) {
      console.log(`"${key}": "${value}"`);
  }
}

getKeys()

ストレージからすべてのキーの配列を取得します。 Promise を返します。

getKeys(): Promise<string[]>;

返品

Promise<string[]>

注釈

API セット: SharedRuntime 1.1、Mailbox 1.10

このメソッドは、Excel、PowerPoint、および Word アドインの SharedRuntime 1.1 要件セットで使用できます。Outlook のメールボックス要件セット 1.10 以降でも使用できます。

重要: Outlook では、サポートは Outlook on Windows に実装されている イベント ベースのライセンス認証 機能でのみ利用できます。 この方法は、Outlook on Mac または Outlook on the web ではサポートされていません。

// Retrieve all keys currently stored in the shared runtime storage.
async function getAllKeys() {
  const keys = await OfficeRuntime.storage.getKeys();

  if (keys.length === 0) {
    console.log('No items in storage.');
    showStatus('Storage is empty', 'info');
  } else {
    console.log(`Found ${keys.length} key(s):\n\n${keys.toString()}`);
  }
}

removeItem(key)

アイテムをキーに基づいてストレージから削除します。 Promise を返します。

removeItem(key: string): Promise<void>;

パラメーター

key

string

削除する項目のキー。 文字列でなければなりません。

返品

Promise<void>

注釈

API セット: SharedRuntime 1.1、Mailbox 1.10

このメソッドは、Excel、PowerPoint、および Word アドインの SharedRuntime 1.1 要件セットで使用できます。Outlook のメールボックス要件セット 1.10 以降でも使用できます。

重要: Outlook では、サポートは Outlook on Windows に実装されている イベント ベースのライセンス認証 機能でのみ利用できます。 この方法は、Outlook on Mac または Outlook on the web ではサポートされていません。

// Delete an item from the shared runtime storage by its key.
async function removeItem() {
    const key = document.getElementById('deleteKey').value.trim();
        
    // Check if key exists first.
    const value = await OfficeRuntime.storage.getItem(key);

    if (value === null) {
        console.log(`Key "${key}" not found`);
    } else {
      await OfficeRuntime.storage.removeItem(key);
      console.log(`Item "${key}" removed successfully`);
    }
}

removeItems(keys)

ストレージから複数のアイテムを削除します。 Promise を返します。

removeItems(keys: string[]): Promise<void>;

パラメーター

keys

string[]

削除するアイテムのキー。 文字列の配列でなければなりません。

返品

Promise<void>

注釈

API セット: SharedRuntime 1.1、Mailbox 1.10

このメソッドは、Excel、PowerPoint、および Word アドインの SharedRuntime 1.1 要件セットで使用できます。Outlook のメールボックス要件セット 1.10 以降でも使用できます。

重要: Outlook では、サポートは Outlook on Windows に実装されている イベント ベースのライセンス認証 機能でのみ利用できます。 この方法は、Outlook on Mac または Outlook on the web ではサポートされていません。

// Delete all the items from the shared runtime storage.
async function clearAllStorage() {
  const keys = await OfficeRuntime.storage.getKeys();
  await OfficeRuntime.storage.removeItems(keys);
  console.log(`All ${keys.length} items cleared from storage`);
}

setItem(key, value)

キーと値のペアをストレージに設定するか、既存のキーと値のペアを更新します。 Promise を返します。

setItem(key: string, value: string): Promise<void>;

パラメーター

key

string

設定する項目のキー。 文字列でなければなりません。

value

string

文字列でなければなりません。

返品

Promise<void>

注釈

API セット: SharedRuntime 1.1、Mailbox 1.10

このメソッドは、Excel、PowerPoint、および Word アドインの SharedRuntime 1.1 要件セットで使用できます。Outlook のメールボックス要件セット 1.10 以降でも使用できます。

重要: Outlook では、サポートは Outlook on Windows に実装されている イベント ベースのライセンス認証 機能でのみ利用できます。 この方法は、Outlook on Mac または Outlook on the web ではサポートされていません。

// Save a key-value pair in the shared runtime storage.
async function storeValue() {
  const key = document.getElementById('createKey').value.trim();
  const value = document.getElementById('createValue').value.trim();

  await OfficeRuntime.storage.setItem(key, value);
}

setItems(keyValues)

複数のアイテムをストレージに設定するか、ストレージ内の複数のアイテムを更新します。 Promise を返します。

setItems(keyValues: { [key: string]: string }): Promise<void>;

パラメーター

keyValues

{ [key: string]: string }

設定するキーと値のペア。 文字列でなければなりません。

返品

Promise<void>

注釈

API セット: SharedRuntime 1.1、Mailbox 1.10

このメソッドは、Excel、PowerPoint、および Word アドインの SharedRuntime 1.1 要件セットで使用できます。Outlook のメールボックス要件セット 1.10 以降でも使用できます。

重要: Outlook では、サポートは Outlook on Windows に実装されている イベント ベースのライセンス認証 機能でのみ利用できます。 この方法は、Outlook on Mac または Outlook on the web ではサポートされていません。

// Save multiple key-value pairs in the shared runtime storage.
async function setDefaultSettings() {
  const demoData = {
      'username': 'JohnDoe',
      'email': 'john.doe@example.com',
      'theme': 'dark',
      'lastLogin': new Date().toISOString(),
      'preferences': JSON.stringify({ notifications: true, language: 'en' })
  };

  await OfficeRuntime.storage.setItems(demoData);
}