PowerPoint.SensitivityLabel class

注意

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

表示演示文稿上的敏感度标签。

扩展

属性

context

与对象关联的请求上下文。 这将加载项的进程连接到 Office 主机应用程序的进程。

方法

getCurrentOrNullObject()

获取用户演示文稿上存在的当前标签信息。 如果当前演示文稿上没有敏感度标签,则返回属性设置为 的true对象isNullObject。 有关详细信息,请参阅 *OrNullObject 方法和属性。

toJSON()

覆盖 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 (JSON.stringify反过来调用 toJSON 传递给它的对象的方法。) 虽然原始 PowerPoint.SensitivityLabel 对象是 API 对象, toJSON 但该方法返回一个纯 JavaScript 对象, (类型化为 PowerPoint.Interfaces.SensitivityLabelData) ,其中包含从原始对象加载的任何子属性的浅层副本。

tryToUpdate(labelId, options)

尝试更新到演示文稿上为用户提供的敏感度标签。 对于启用 ABAC 的标签,请通过 options.abacAttributes传递所需的属性选择。

属性详细信息

context

注意

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

与对象关联的请求上下文。 这将加载项的进程连接到 Office 主机应用程序的进程。

context: RequestContext;

属性值

方法详细信息

getCurrentOrNullObject()

注意

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

获取用户演示文稿上存在的当前标签信息。 如果当前演示文稿上没有敏感度标签,则返回属性设置为 的true对象isNullObject。 有关详细信息,请参阅 *OrNullObject 方法和属性。

getCurrentOrNullObject(): PowerPoint.SensitivityLabelDetails;

返回

当前 SensitivityLabelDetails 对象。

注解

API 集:PowerPointApi BETA (仅预览版)

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/preview-apis/manage-sensitivity-labels.yaml

await PowerPoint.run(async (context) => {
  // Get the sensitivity label currently applied to the presentation.
  const presentation: PowerPoint.Presentation = context.presentation;
  const presentationLabel: PowerPoint.SensitivityLabel = presentation.sensitivityLabel;

  const currentLabel: PowerPoint.SensitivityLabelDetails = presentationLabel.getCurrentOrNullObject();
  // Load the properties of the label currently applied to the presentation.
  currentLabel.load(
    "color,id,isAbacAttributesRequired,isAbacEnabled,isEnabled,name,order,protectionType,siteId,tooltip"
  );
  await context.sync();

  if (currentLabel.isNullObject) {
    console.log("The presentation doesn't have a sensitivity label.");
    return;
  }

  // Get ABAC values when enabled for the label.
  let abacAttributeValues: PowerPoint.SensitivityLabelAbacAttributeValue[] = [];
  if (currentLabel.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: PowerPoint.SensitivityLabelAbacAttributeValue) =>
            `${attributeValue.displayName} (ID: ${attributeValue.id}, order: ${attributeValue.displayOrder}, active: ${attributeValue.isActive ? "Yes" : "No"})`
        )
        .join(", ")
    : "None";

  let protectionDescription: string;
  switch (currentLabel.protectionType) {
    case PowerPoint.SensitivityLabelProtectionType.adminDefined:
      protectionDescription = "Defined by an administrator";
      break;
    case PowerPoint.SensitivityLabelProtectionType.userDefined:
      protectionDescription = "Defined by the user";
      break;
    case PowerPoint.SensitivityLabelProtectionType.noProtection:
      protectionDescription = "No protection";
      break;
    default:
      protectionDescription = `Unknown (${currentLabel.protectionType})`;
      break;
  }

  console.log(
    `Current presentation 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。

覆盖 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 (JSON.stringify反过来调用 toJSON 传递给它的对象的方法。) 虽然原始 PowerPoint.SensitivityLabel 对象是 API 对象, toJSON 但该方法返回一个纯 JavaScript 对象, (类型化为 PowerPoint.Interfaces.SensitivityLabelData) ,其中包含从原始对象加载的任何子属性的浅层副本。

toJSON(): {
            [key: string]: string;
        };

返回

{ [key: string]: string; }

tryToUpdate(labelId, options)

注意

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

尝试更新到演示文稿上为用户提供的敏感度标签。 对于启用 ABAC 的标签,请通过 options.abacAttributes传递所需的属性选择。

tryToUpdate(labelId: string, options?: PowerPoint.SensitivityLabelTryUpdateOptions): OfficeExtension.ClientResult<PowerPoint.SensitivityLabelUpdateResult>;

参数

labelId

string

要应用的标签的 ID。

options
PowerPoint.SensitivityLabelTryUpdateOptions

可选。 影响更新的其他输入,例如启用 ABAC 的标签的 ABAC 属性选择。

返回

SensitivityLabelUpdateResult对象。

注解

API 集:PowerPointApi BETA (仅预览版)

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/preview-apis/manage-sensitivity-labels.yaml

await PowerPoint.run(async (context) => {
  // Apply the selected sensitivity label to the presentation.
  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 presentation: PowerPoint.Presentation = context.presentation;
  const presentationLabel: PowerPoint.SensitivityLabel = presentation.sensitivityLabel;

  const updateResult: OfficeExtension.ClientResult<PowerPoint.SensitivityLabelUpdateResult> =
    presentationLabel.tryToUpdate(labelId);
  await context.sync();

  if (updateResult.value.status === PowerPoint.SensitivityLabelUpdateStatus.success) {
    console.log("Applied the sensitivity label to the presentation.");
  } else {
    console.error(`The sensitivity label wasn't applied. Status: ${updateResult.value.status}`);
  }
});