Excel.SensitivityLabel class
注意
この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。
ブックの秘密度ラベルを表します。
- Extends
プロパティ
| context | オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。 |
メソッド
| get |
ユーザーのブックに存在する現在のラベル情報を取得します。 現在のブックに秘密度ラベルがない場合は、 |
| toJSON() | API オブジェクトが |
| try |
ユーザーのブックで指定された秘密度ラベルに更新しようとします。 ABAC 対応ラベルの場合は、目的の属性選択を |
プロパティの詳細
context
注意
この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。
オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。
context: RequestContext;
プロパティ値
メソッドの詳細
getCurrentOrNullObject()
注意
この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。
ユーザーのブックに存在する現在のラベル情報を取得します。 現在のブックに秘密度ラベルがない場合は、true に設定された isNullObject プロパティを持つオブジェクトが返されます。 詳細については、「 *OrNullObject のメソッドとプロパティ」を参照してください。
getCurrentOrNullObject(): Excel.SensitivityLabelDetails;
戻り値
現在の SensitivityLabelDetails オブジェクト。
注釈
API セット: ExcelApi ベータ版 (プレビューのみ)
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/98-preview-apis/manage-sensitivity-labels.yaml
// Get the sensitivity label currently applied to the workbook.
await Excel.run(async (context) => {
const workbook: Excel.Workbook = context.workbook;
const workbookLabel: Excel.SensitivityLabel = workbook.sensitivityLabel;
const currentLabel: Excel.SensitivityLabelDetails = workbookLabel.getCurrentOrNullObject();
currentLabel.load(
"color,id,isAbacAttributesRequired,isAbacEnabled,isEnabled,name,order,protectionType,siteId,tooltip"
);
await context.sync();
if (currentLabel.isNullObject) {
console.log("The workbook doesn't have a sensitivity label.");
return;
}
// Get ABAC values only when enabled for the label.
let abacAttributeValues: Excel.SensitivityLabelAbacAttributeValue[] = [];
if (currentLabel.isAbacEnabled) {
currentLabel.load("abacAttributeValues");
await context.sync();
abacAttributeValues = currentLabel.abacAttributeValues;
}
const attributeValues = abacAttributeValues.length
? abacAttributeValues
.map((attributeValue: Excel.SensitivityLabelAbacAttributeValue) =>
`${attributeValue.displayName} (ID: ${attributeValue.id}, ` +
`order: ${attributeValue.displayOrder}, active: ${attributeValue.isActive ? "Yes" : "No"})`)
.join(", ")
: "None";
let protectionDescription: string;
switch (currentLabel.protectionType) {
case Excel.SensitivityLabelProtectionType.adminDefined:
protectionDescription = "Defined by an administrator";
break;
case Excel.SensitivityLabelProtectionType.userDefined:
protectionDescription = "Defined by the user";
break;
case Excel.SensitivityLabelProtectionType.noProtection:
protectionDescription = "No protection";
break;
default:
protectionDescription = `Unknown (${currentLabel.protectionType})`;
break;
}
console.log(
`Current workbook 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}`
);
});
toJSON()
注意
この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。
API オブジェクトが JSON.stringify() に渡されるときに、より有用な出力を提供するために、JavaScript toJSON() メソッドをオーバーライドします。 (次に、JSON.stringify渡されたオブジェクトの toJSON メソッドを呼び出します)。元の Excel.SensitivityLabel オブジェクトが API オブジェクトであるのに対し、 toJSON メソッドは、元のオブジェクトから読み込まれた子プロパティの浅いコピーを含むプレーンな JavaScript オブジェクト ( Excel.Interfaces.SensitivityLabelData と型指定) を返します。
toJSON(): {
[key: string]: string;
};
戻り値
{ [key: string]: string; }
tryToUpdate(labelId, options)
注意
この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。
ユーザーのブックで指定された秘密度ラベルに更新しようとします。 ABAC 対応ラベルの場合は、目的の属性選択を options.abacAttributes 経由で渡します。
tryToUpdate(labelId: string, options?: Excel.SensitivityLabelTryUpdateOptions): OfficeExtension.ClientResult<Excel.SensitivityLabelUpdateResult>;
パラメーター
- labelId
-
string
適用するラベルの ID。
省略可能。 ABAC 対応ラベルの ABAC 属性の選択など、更新に影響する追加の入力。
戻り値
SensitivityLabelUpdateResult オブジェクト。
注釈
API セット: ExcelApi ベータ版 (プレビューのみ)
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/98-preview-apis/manage-sensitivity-labels.yaml
// Apply the selected sensitivity label to the entire workbook.
await Excel.run(async (context) => {
const labelId = (document.getElementById("label-id") as HTMLSelectElement).value;
if (!labelId) {
console.warn("Get available labels and select a label first.");
return;
}
const workbook: Excel.Workbook = context.workbook;
const workbookLabel: Excel.SensitivityLabel = workbook.sensitivityLabel;
const updateResult: OfficeExtension.ClientResult<Excel.SensitivityLabelUpdateResult> =
workbookLabel.tryToUpdate(labelId);
await context.sync();
if (updateResult.value.status === Excel.SensitivityLabelUpdateStatus.success) {
console.log("Applied the sensitivity label to the workbook.");
} else {
console.error(`The sensitivity label wasn't applied. Status: ${updateResult.value.status}`);
}
});