Word.Coauthoring class

Coauthoring オブジェクトを表します。 これにより、共同編集を通じて行われたドキュメント内の更新、変更、競合、その他の相互作用が追跡されます。

Extends

注釈

API セット: WordApiDesktop 1.4

使用元

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/05-coauthoring/manage-coauthors.yaml

// Gets the coauthoring capabilities and pending-update status of the document.
await Word.run(async (context) => {
  const coauthoring: Word.Coauthoring = context.document.coauthoring;
  coauthoring.load("canCoauthor,canMerge,pendingUpdates");
  await context.sync();

  console.log("Can coauthor:", coauthoring.canCoauthor);
  console.log("Can merge:", coauthoring.canMerge);
  console.log("Pending updates:", coauthoring.pendingUpdates);
});

プロパティ

authors

現在ドキュメントを編集しているすべての共同作成者を表す CoauthorCollection オブジェクトを取得します。

canCoauthor

このドキュメントを共同編集できるかどうかを取得します。

canMerge

文書を自動的に結合できるかどうかを取得します。

conflicts

ドキュメント内のすべての競合を表す ConflictCollection オブジェクトを取得します。

context

オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。

locks

ドキュメント内のロックを表す CoauthoringLockCollection オブジェクトを取得します。

me

現在のユーザーを表す Coauthor オブジェクトを取得します。

pendingUpdates

ドキュメントに、承認されていない保留中の更新があるかどうかを取得します。

updates

ドキュメントにマージされた最新の更新プログラムを表す CoauthoringUpdateCollection オブジェクトを取得します。

メソッド

load(options)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(propertyNames)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(propertyNamesAndPaths)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

toJSON()

API オブジェクトが JSON.stringify() に渡されるときに、より有用な出力を提供するために、JavaScript toJSON() メソッドをオーバーライドします。 (次に、JSON.stringify渡されたオブジェクトの toJSON メソッドを呼び出します)。元の Word.Coauthoring オブジェクトが API オブジェクトであるのに対し、 toJSON メソッドは、元のオブジェクトから読み込まれた子プロパティの浅いコピーを含むプレーンな JavaScript オブジェクト ( Word.Interfaces.CoauthoringData と型指定) を返します。

track()

ドキュメントの環境変更に基づいて自動的に調整する目的でオブジェクトを追跡します。 この呼び出しは、 context.trackedObjects.add(thisObject) の短縮形です。 このオブジェクトを .sync 呼び出しと ".run" バッチの連続実行の外部で使用していて、プロパティを設定したり、オブジェクトでメソッドを呼び出したりするときに "InvalidObjectPath" エラーが発生する場合は、オブジェクトが最初に作成されたときに、追跡対象のオブジェクト コレクションにオブジェクトを追加する必要があります。 このオブジェクトがコレクションの一部である場合は、親コレクションも追跡する必要があります。

untrack()

前に追跡されていた場合、このオブジェクトに関連付けられているメモリを解放します。 この呼び出しは、 context.trackedObjects.remove(thisObject) の省略形です。 追跡対象オブジェクトが多いとホスト アプリケーションの動作が遅くなります。追加したオブジェクトが不要になったら、必ずそれを解放してください。 メモリ リリースを有効にする前に、 context.sync() を呼び出す必要があります。

プロパティの詳細

authors

現在ドキュメントを編集しているすべての共同作成者を表す CoauthorCollection オブジェクトを取得します。

readonly authors: Word.CoauthorCollection;

プロパティ値

注釈

API セット: WordApiDesktop 1.4

canCoauthor

このドキュメントを共同編集できるかどうかを取得します。

readonly canCoauthor: boolean;

プロパティ値

boolean

注釈

API セット: WordApiDesktop 1.4

canMerge

文書を自動的に結合できるかどうかを取得します。

readonly canMerge: boolean;

プロパティ値

boolean

注釈

API セット: WordApiDesktop 1.4

conflicts

ドキュメント内のすべての競合を表す ConflictCollection オブジェクトを取得します。

readonly conflicts: Word.ConflictCollection;

プロパティ値

注釈

API セット: WordApiDesktop 1.4

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/05-coauthoring/manage-coauthoring-conflicts.yaml

// Gets all coauthoring conflicts in the document.
await Word.run(async (context) => {
  const conflicts: Word.ConflictCollection = context.document.coauthoring.conflicts;
  conflicts.load("items/type");
  await context.sync();

  if (conflicts.items.length === 0) {
    console.log("No conflicts found in the document.");
    return;
  }

  console.log(`Found ${conflicts.items.length} conflict(s):`);
  for (let i = 0; i < conflicts.items.length; i++) {
    console.log(`  Conflict ${i + 1}: type = ${conflicts.items[i].type}`);
  }
});

context

オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。

context: RequestContext;

プロパティ値

locks

ドキュメント内のロックを表す CoauthoringLockCollection オブジェクトを取得します。

readonly locks: Word.CoauthoringLockCollection;

プロパティ値

注釈

API セット: WordApiDesktop 1.4

この API は、レガシ共同編集ロックでのみ機能します。 ロック管理がサービスによって自動的に処理される最新の OneDrive や SharePoint の共同編集には適用されません。 モダン ドキュメントの呼び出しは、 GeneralException エラーで失敗します。

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/05-coauthoring/manage-coauthoring-locks.yaml

// Adds a lock to the paragraph at the insertion point.
// Requires the document to be saved to OneDrive or SharePoint.
await Word.run(async (context) => {
  const coauthoring: Word.Coauthoring = context.document.coauthoring;
  coauthoring.load("canCoauthor");
  await context.sync();

  if (!coauthoring.canCoauthor) {
    console.warn("This document doesn't support coauthoring. Save it to OneDrive or SharePoint and try again.");
    return;
  }

  const locks: Word.CoauthoringLockCollection = coauthoring.locks;
  locks.add();
  await context.sync();

  console.log("Lock added.");
});

me

現在のユーザーを表す Coauthor オブジェクトを取得します。

readonly me: Word.Coauthor;

プロパティ値

注釈

API セット: WordApiDesktop 1.4

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/05-coauthoring/manage-coauthors.yaml

// Gets the current user's coauthor information.
await Word.run(async (context) => {
  const me: Word.Coauthor = context.document.coauthoring.me;
  me.load("name,emailAddress,id");
  await context.sync();

  console.log("Current user:", me.name);
  console.log("Email:", me.emailAddress);
  console.log("ID:", me.id);
});

pendingUpdates

ドキュメントに、承認されていない保留中の更新があるかどうかを取得します。

readonly pendingUpdates: boolean;

プロパティ値

boolean

注釈

API セット: WordApiDesktop 1.4

updates

ドキュメントにマージされた最新の更新プログラムを表す CoauthoringUpdateCollection オブジェクトを取得します。

readonly updates: Word.CoauthoringUpdateCollection;

プロパティ値

注釈

API セット: WordApiDesktop 1.4

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/05-coauthoring/get-coauthoring-updates.yaml

// Gets the ranges affected by the most recent coauthoring updates merged into the document.
await Word.run(async (context) => {
  const updates: Word.CoauthoringUpdateCollection = context.document.coauthoring.updates;
  updates.load("items/range");
  await context.sync();

  if (updates.items.length === 0) {
    console.log("No recent coauthoring updates found.");
    return;
  }

  console.log(`Found ${updates.items.length} recent update(s).`);

  const ranges = updates.items.map((u) => u.range);
  ranges.forEach((r) => r.load("text"));
  await context.sync();

  ranges.forEach((range, i) => {
    console.log(`  Update ${i + 1}: "${range.text}"`);
  });
});

メソッドの詳細

load(options)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(options?: Word.Interfaces.CoauthoringLoadOptions): Word.Coauthoring;

パラメーター

options
Word.Interfaces.CoauthoringLoadOptions

読み込むオブジェクトのプロパティのオプションを指定します。

返品

load(propertyNames)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(propertyNames?: string | string[]): Word.Coauthoring;

パラメーター

propertyNames

string | string[]

読み込むプロパティを指定するコンマ区切りの文字列または文字列の配列。

返品

load(propertyNamesAndPaths)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): Word.Coauthoring;

パラメーター

propertyNamesAndPaths

{ select?: string; expand?: string; }

propertyNamesAndPaths.select は読み込むプロパティを指定するコンマ区切りの文字列であり、 propertyNamesAndPaths.expand は読み込むナビゲーションのプロパティを指定するコンマ区切りの文字列です。

返品

toJSON()

API オブジェクトが JSON.stringify() に渡されるときに、より有用な出力を提供するために、JavaScript toJSON() メソッドをオーバーライドします。 (次に、JSON.stringify渡されたオブジェクトの toJSON メソッドを呼び出します)。元の Word.Coauthoring オブジェクトが API オブジェクトであるのに対し、 toJSON メソッドは、元のオブジェクトから読み込まれた子プロパティの浅いコピーを含むプレーンな JavaScript オブジェクト ( Word.Interfaces.CoauthoringData と型指定) を返します。

toJSON(): Word.Interfaces.CoauthoringData;

返品

track()

ドキュメントの環境変更に基づいて自動的に調整する目的でオブジェクトを追跡します。 この呼び出しは、 context.trackedObjects.add(thisObject) の短縮形です。 このオブジェクトを .sync 呼び出しと ".run" バッチの連続実行の外部で使用していて、プロパティを設定したり、オブジェクトでメソッドを呼び出したりするときに "InvalidObjectPath" エラーが発生する場合は、オブジェクトが最初に作成されたときに、追跡対象のオブジェクト コレクションにオブジェクトを追加する必要があります。 このオブジェクトがコレクションの一部である場合は、親コレクションも追跡する必要があります。

track(): Word.Coauthoring;

返品

untrack()

前に追跡されていた場合、このオブジェクトに関連付けられているメモリを解放します。 この呼び出しは、 context.trackedObjects.remove(thisObject) の省略形です。 追跡対象オブジェクトが多いとホスト アプリケーションの動作が遅くなります。追加したオブジェクトが不要になったら、必ずそれを解放してください。 メモリ リリースを有効にする前に、 context.sync() を呼び出す必要があります。

untrack(): Word.Coauthoring;

返品