PowerPoint.Hyperlink class

表示单个超链接。

扩展

注解

API 集:PowerPointApi 1.6

使用方

示例

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

// Gets the hyperlinks found in the first selected slide.
await PowerPoint.run(async (context) => {
  const slide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
  const hyperlinks: PowerPoint.HyperlinkCollection = slide.hyperlinks.load("address,screenTip");
  const hyperlinksCount = hyperlinks.getCount();
  await context.sync();

  console.log(
    `${hyperlinksCount.value} hyperlinks found in first selected slide${hyperlinksCount.value === 0 ? "." : ":"}`,
  );
  for (let link of hyperlinks.items) {
    console.log(`Address: "${link.address}" (screen tip: "${link.screenTip}").`);
  }
});

属性

address

指定超链接的地址,可以是 URL、文件名或文件路径,也可以是具有 URI 方案的 mailto 电子邮件地址。

context

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

screenTip

指定将鼠标悬停在超链接上时显示的字符串。

type

返回应用超链接的对象的类型。 有关详细信息,请参阅 PowerPoint.HyperlinkType

方法

delete()

删除超链接。

getLinkedShapeOrNullObject()

返回应用了超链接的 PowerPoint.Shape 对象。 如果超链接不是类型 shape,或者它位于当前不支持 PowerPoint.Shape 的域中,则此方法将返回其 isNullObject 属性设置为 true的对象。 有关详细信息,请参阅 *OrNullObject 方法和属性

getLinkedTextRangeOrNullObject()

返回应用超链接到的 PowerPoint.TextRange 对象。 如果超链接不是类型 textRange,或者它位于当前不支持 PowerPoint.TextRange 的域中,则此方法返回其 isNullObject 属性设置为 true的对象。 有关详细信息,请参阅 *OrNullObject 方法和属性

load(options)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNames)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNamesAndPaths)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

toJSON()

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

属性详细信息

指定超链接的地址,可以是 URL、文件名或文件路径,也可以是具有 URI 方案的 mailto 电子邮件地址。

address: string;

属性值

string

注解

API 集:PowerPointApi 1.6

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

context: RequestContext;

属性值

指定将鼠标悬停在超链接上时显示的字符串。

screenTip: string;

属性值

string

注解

API 集:PowerPointApi 1.6

返回应用超链接的对象的类型。 有关详细信息,请参阅 PowerPoint.HyperlinkType

readonly type: PowerPoint.HyperlinkType | "TextRange" | "Shape";

属性值

PowerPoint.HyperlinkType | "TextRange" | "Shape"

注解

API 集:PowerPointApi 1.10

方法详细信息

删除超链接。

delete(): void;

返回

void

注解

API 集:PowerPointApi 1.10

示例

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

// Deletes the first hyperlink found in the selected text on the current slide.
await PowerPoint.run(async (context) => {
  const textRange: PowerPoint.TextRange = context.presentation.getSelectedTextRange().load("text");
  let hyperlink: PowerPoint.Hyperlink = textRange.hyperlinks.getItemAt(0).load("address,screenTip");
  try {
    await context.sync();
  } catch {
    console.warn(
      "Confirm that you have at least one slide and you've selected a contiguous range of text containing at least one hyperlink on the active slide.",
    );
    return;
  }

  console.log(
    `About to delete first link "${hyperlink.address}" (screen tip: "${hyperlink.screenTip}") found in the selected text "${textRange.text}".`,
  );

  hyperlink.delete();

  console.log(`Deleted first link found in the selected text "${textRange.text}".`);
});

返回应用了超链接的 PowerPoint.Shape 对象。 如果超链接不是类型 shape,或者它位于当前不支持 PowerPoint.Shape 的域中,则此方法将返回其 isNullObject 属性设置为 true的对象。 有关详细信息,请参阅 *OrNullObject 方法和属性

getLinkedShapeOrNullObject(): PowerPoint.Shape;

返回

注解

API 集:PowerPointApi 1.10

返回应用超链接到的 PowerPoint.TextRange 对象。 如果超链接不是类型 textRange,或者它位于当前不支持 PowerPoint.TextRange 的域中,则此方法返回其 isNullObject 属性设置为 true的对象。 有关详细信息,请参阅 *OrNullObject 方法和属性

getLinkedTextRangeOrNullObject(): PowerPoint.TextRange;

返回

注解

API 集:PowerPointApi 1.10

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(options?: PowerPoint.Interfaces.HyperlinkLoadOptions): PowerPoint.Hyperlink;

参数

options
PowerPoint.Interfaces.HyperlinkLoadOptions

为要加载的对象属性提供选项。

返回

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNames?: string | string[]): PowerPoint.Hyperlink;

参数

propertyNames

string | string[]

指定要加载的属性的逗号分隔的字符串或字符串数组。

返回

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): PowerPoint.Hyperlink;

参数

propertyNamesAndPaths

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

propertyNamesAndPaths.select 是指定要加载的属性的逗号分隔字符串,以及 propertyNamesAndPaths.expand 指定要加载的导航属性的逗号分隔字符串。

返回

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

toJSON(): PowerPoint.Interfaces.HyperlinkData;

返回