Class Link

連結

超文字連結。

方法

方法傳回類型簡短說明
getLinkType()LinkType傳回 LinkType
getLinkedSlide()Slide|null如果存在非網址連結類型,則傳回連結的 Slide
getSlideId()String|null如果 LinkType 不是 LinkType.SLIDE_ID,則傳回連結的 Slidenull 的 ID。
getSlideIndex()Integer|null如果 LinkType 不是 LinkType.SLIDE_INDEX,則傳回連結 Slidenull 的索引 (從零開始計算)。
getSlidePosition()SlidePosition|null如果 LinkType 不是 LinkType.SLIDE_POSITION,則傳回連結的 SlidenullSlidePosition
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()

如果 LinkType 不是 LinkType.SLIDE_ID,則傳回連結的 Slidenull 的 ID。

請注意,傳回的 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()

如果 LinkType 不是 LinkType.SLIDE_INDEX,則傳回連結 Slidenull 的索引 (從零開始計算)。

請注意,傳回索引的投影片可能不存在。

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()

如果 LinkType 不是 LinkType.SLIDE_POSITION,則傳回連結的 SlidenullSlidePosition

請注意,傳回相對位置的投影片可能不存在。

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()

傳回外部網頁的網址,或 null (如果 LinkType 不是 LinkType.URL)。

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