Class Link

链接

超文本链接。

方法

方法返回值类型简介
getLinkType()LinkType返回 LinkType
getLinkedSlide()Slide|null返回非网址链接类型的链接 Slide(如果存在)。
getSlideId()String|null返回链接 Slide 的 ID;如果 LinkType 不是 LinkType.SLIDE_ID,则返回 null
getSlideIndex()Integer|null返回链接 Slide 的从零开始的索引;如果 LinkType 不是 LinkType.SLIDE_INDEX,则返回 null
getSlidePosition()SlidePosition|null返回链接 SlideSlidePosition;如果 LinkType 不是 LinkType.SLIDE_POSITION,则返回 null
getUrl()String|null返回外部网页的网址;如果 LinkType 不是 LinkType.URL,则返回 null

详细文档

getLinkType()

返回 LinkType

const shape = SlidesApp.getActivePresentation().getSlides()[0].getShapes()[0];
const link = shape.getLink();
if (link != null) {
  Logger.log(`Shape has a link of type: ${link.getLinkType()}`);
}

返回

LinkType

授权

使用此方法需要获得以下一个或多个范围的授权的脚本:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

getLinkedSlide()

返回非网址链接类型的链接 Slide(如果存在)。如果幻灯片在演示文稿中不存在,或者 LinkTypeLinkType.URL,则返回 null

const shape = SlidesApp.getActivePresentation().getSlides()[0].getShapes()[0];
const link = shape.getLink();
if (link != null && link.getLinkType() !== SlidesApp.LinkType.URL) {
  Logger.log(`Shape has link to slide: ${link.getLinkedSlide()}`);
}

返回

Slide|null

授权

使用此方法需要获得以下一个或多个范围的授权的脚本:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

getSlideId()

返回链接 Slide 的 ID;如果 LinkType 不是 LinkType.SLIDE_ID,则返回 null

请注意,返回的 ID 对应的幻灯片可能不存在。

const shape = SlidesApp.getActivePresentation().getSlides()[0].getShapes()[0];
const link = shape.getLink();
if (link != null && link.getLinkType() === SlidesApp.LinkType.SLIDE_ID) {
  Logger.log(`Shape has link to slide with ID: ${link.getSlideId()}`);
}

返回

String|null

授权

使用此方法需要获得以下一个或多个范围的授权的脚本:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

getSlideIndex()

返回链接的从零开始的索引 Slidenull;如果 LinkType 不是 LinkType.SLIDE_INDEX,则返回 。

请注意,返回的索引处的幻灯片可能不存在。

const shape = SlidesApp.getActivePresentation().getSlides()[0].getShapes()[0];
const link = shape.getLink();
if (link != null && link.getLinkType() === SlidesApp.LinkType.SLIDE_INDEX) {
  Logger.log(`Shape has link to slide with index: ${link.getSlideIndex()}`);
}

返回

Integer|null

授权

使用此方法需要获得以下一个或多个范围的授权的脚本:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

getSlidePosition()

返回链接 SlideSlidePosition;如果 LinkType 不是 LinkType.SLIDE_POSITION,则返回 null

请注意,返回的相对位置对应的幻灯片可能不存在。

const shape = SlidesApp.getActivePresentation().getSlides()[0].getShapes()[0];
const link = shape.getLink();
if (link != null && link.getLinkType() === SlidesApp.LinkType.SLIDE_POSITION) {
  Logger.log(
      `Shape has link to slide with relative position: ${
          link.getSlidePosition()}`,
  );
}

返回

SlidePosition|null

授权

使用此方法需要获得以下一个或多个范围的授权的脚本:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

getUrl()

返回外部网页的网址;如果 LinkType 不是 LinkType.URL,则返回 null

const shape = SlidesApp.getActivePresentation().getSlides()[0].getShapes()[0];
const link = shape.getLink();
if (link != null && link.getLinkType() === SlidesApp.LinkType.URL) {
  Logger.log(`Shape has link to URL: ${link.getUrl()}`);
}

返回

String|null

授权

使用此方法需要获得以下一个或多个范围的授权的脚本:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations