Word.SensitivityLabel class
注意
この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。
ドキュメントの秘密度ラベルを表します。
- Extends
プロパティ
| context | オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。 |
メソッド
| get |
ユーザーのドキュメントに存在する現在のラベル情報を取得します。 |
| load(property |
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
| load(property |
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
| toJSON() | API オブジェクトが |
| track() | ドキュメントの環境変更に基づいて自動的に調整する目的でオブジェクトを追跡します。 この呼び出しは、 context.trackedObjects.add(thisObject) の短縮形です。 このオブジェクトを |
| try |
ユーザーのドキュメントで指定された秘密度ラベルに更新しようとします。 |
| untrack() | 前に追跡されていた場合、このオブジェクトに関連付けられているメモリを解放します。 この呼び出しは、 context.trackedObjects.remove(thisObject) の省略形です。 追跡対象オブジェクトが多いとホスト アプリケーションの動作が遅くなります。追加したオブジェクトが不要になったら、必ずそれを解放してください。 メモリ リリースを有効にする前に、 |
プロパティの詳細
context
注意
この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。
オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。
context: RequestContext;
プロパティ値
メソッドの詳細
getCurrentOrNullObject()
注意
この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。
ユーザーのドキュメントに存在する現在のラベル情報を取得します。
getCurrentOrNullObject(): Word.SensitivityLabelDetails;
戻り値
注釈
API セット: WordApi ベータ版 (プレビューのみ)
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/99-preview-apis/manage-sensitivity-labels.yaml
await Word.run(async (context) => {
// Get the sensitivity label currently applied to the document.
const wordDocument: Word.Document = context.document;
const documentLabel: Word.SensitivityLabel = wordDocument.sensitivityLabel;
const currentLabel: Word.SensitivityLabelDetails = documentLabel.getCurrentOrNullObject();
// Load the properties of the label currently applied to the document.
currentLabel.load(
"color,id,isAbacAttributesRequired,isAbacEnabled,isEnabled,name,order,protectionType,siteId,tooltip"
);
await context.sync();
if (currentLabel.isNullObject) {
console.log("The document doesn't have a sensitivity label.");
return;
}
// Load ABAC values when supported.
let abacAttributeValues: Word.SensitivityLabelAbacAttributeValue[] = [];
const isAbacEnabled = currentLabel.isAbacEnabled;
if (isAbacEnabled) {
currentLabel.load("abacAttributeValues");
await context.sync();
abacAttributeValues = currentLabel.abacAttributeValues;
}
// Display the loaded properties of the current label.
const attributeValues = abacAttributeValues.length
? abacAttributeValues
.map(
(attributeValue: Word.SensitivityLabelAbacAttributeValue) =>
`${attributeValue.displayName} (ID: ${attributeValue.id}, order: ${attributeValue.displayOrder}, active: ${attributeValue.isActive ? "Yes" : "No"})`
)
.join(", ")
: "None";
let protectionDescription: string;
switch (currentLabel.protectionType) {
case Word.SensitivityLabelProtectionType.adminDefined:
protectionDescription = "Defined by an administrator";
break;
case Word.SensitivityLabelProtectionType.userDefined:
protectionDescription = "Defined by the user";
break;
case Word.SensitivityLabelProtectionType.noProtection:
protectionDescription = "No protection";
break;
default:
protectionDescription = `Unknown (${currentLabel.protectionType})`;
break;
}
console.log(
`Current document sensitivity label:\n\n${currentLabel.name}\n` +
` ID: ${currentLabel.id}\n` +
` Site ID: ${currentLabel.siteId}\n` +
` Tooltip: ${currentLabel.tooltip}\n` +
` Color: ${currentLabel.color}\n` +
` Enabled: ${currentLabel.isEnabled ? "Yes" : "No"}\n` +
` Display order: ${currentLabel.order}\n` +
` ABAC enabled: ${currentLabel.isAbacEnabled ? "Yes" : "No"}\n` +
` ABAC attributes required: ${currentLabel.isAbacAttributesRequired ? "Yes" : "No"}\n` +
` ABAC attribute values: ${attributeValues}\n` +
` Protection type: ${protectionDescription}`
);
});
load(propertyNames)
注意
この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。
load(propertyNames?: string | string[]): Word.SensitivityLabel;
パラメーター
- propertyNames
-
string | string[]
読み込むプロパティを指定するコンマ区切りの文字列または文字列の配列。
戻り値
load(propertyNamesAndPaths)
注意
この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。
load(propertyNamesAndPaths?: {
select?: string;
expand?: string;
}): Word.SensitivityLabel;
パラメーター
- propertyNamesAndPaths
-
{ select?: string; expand?: string; }
propertyNamesAndPaths.select は読み込むプロパティを指定するコンマ区切りの文字列であり、 propertyNamesAndPaths.expand は読み込むナビゲーションのプロパティを指定するコンマ区切りの文字列です。
戻り値
toJSON()
注意
この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。
API オブジェクトが JSON.stringify() に渡されるときに、より有用な出力を提供するために、JavaScript toJSON() メソッドをオーバーライドします。 (次に、JSON.stringify渡されたオブジェクトの toJSON メソッドを呼び出します)。元の Word.SensitivityLabel オブジェクトが API オブジェクトであるのに対し、 toJSON メソッドは、元のオブジェクトから読み込まれた子プロパティの浅いコピーを含むプレーンな JavaScript オブジェクト ( Word.Interfaces.SensitivityLabelData と型指定) を返します。
toJSON(): {
[key: string]: string;
};
戻り値
{ [key: string]: string; }
track()
注意
この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。
ドキュメントの環境変更に基づいて自動的に調整する目的でオブジェクトを追跡します。 この呼び出しは、 context.trackedObjects.add(thisObject) の短縮形です。 このオブジェクトを .sync 呼び出しと ".run" バッチの連続実行の外部で使用していて、プロパティを設定したり、オブジェクトでメソッドを呼び出したりするときに "InvalidObjectPath" エラーが発生する場合は、オブジェクトが最初に作成されたときに、追跡対象のオブジェクト コレクションにオブジェクトを追加する必要があります。 このオブジェクトがコレクションの一部である場合は、親コレクションも追跡する必要があります。
track(): Word.SensitivityLabel;
戻り値
tryToUpdate(LabelId, Options)
注意
この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。
ユーザーのドキュメントで指定された秘密度ラベルに更新しようとします。
tryToUpdate(LabelId: string, Options?: Word.SensitivityLabelTryUpdateOptions): OfficeExtension.ClientResult<Word.SensitivityLabelUpdateResult>;
パラメーター
- LabelId
-
string
適用するラベルの ID。
省略可能。 ABAC 属性などの追加入力。
戻り値
注釈
API セット: WordApi ベータ版 (プレビューのみ)
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/99-preview-apis/manage-sensitivity-labels.yaml
// Apply the selected sensitivity label to the document.
await Word.run(async (context) => {
const labelId = (document.getElementById("label-id") as HTMLSelectElement).value;
if (!labelId) {
console.warn("Get the available labels, and then select a label to apply.");
return;
}
const wordDocument: Word.Document = context.document;
const documentLabel: Word.SensitivityLabel = wordDocument.sensitivityLabel;
const updateResult: OfficeExtension.ClientResult<Word.SensitivityLabelUpdateResult> =
documentLabel.tryToUpdate(labelId);
await context.sync();
if (updateResult.value.status === Word.SensitivityLabelUpdateStatus.success) {
console.log("Applied the sensitivity label to the document.");
} else {
console.error(`The sensitivity label wasn't applied. Status: ${updateResult.value.status}`);
}
});
untrack()
注意
この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。
前に追跡されていた場合、このオブジェクトに関連付けられているメモリを解放します。 この呼び出しは、 context.trackedObjects.remove(thisObject) の省略形です。 追跡対象オブジェクトが多いとホスト アプリケーションの動作が遅くなります。追加したオブジェクトが不要になったら、必ずそれを解放してください。 メモリ リリースを有効にする前に、 context.sync() を呼び出す必要があります。
untrack(): Word.SensitivityLabel;