是否可以将图形从幻灯片移动到另一个?

时间:2020-09-11 11:31:41

标签: google-slides-api

我在NodeJS服务器上使用Google Slides API编辑演示文稿,但在文档中找不到任何关于将对象移至另一张幻灯片(例如Shape)的内容。谢谢。

1 个答案:

答案 0 :(得分:2)

答案:

您必须通过从presentations.pages.get的响应中获取形状,将其删除并用presentations.batchUpdate插入来做到这一点。

更多信息:

实际上,为了使用API​​将对象从一张幻灯片“移动”到另一张幻灯片,实际上,您必须提出两个请求:一个删除当前对象,另一个将其插入新幻灯片。

首先,您需要向presentations.pages.get发出请求才能获取页面中的所有PageElement对象。根据{{​​3}},“形状”是PageElement对象的实例,该对象代表幻灯片上的形状。

presentations.pages.get的响应将是documentation

{
  "objectId": string,
  "pageType": enum (PageType),
  "pageElements": [
    {
      object (PageElement)
    }
  ],
  "revisionId": string,
  "pageProperties": {
    object (PageProperties)
  },

  // Union field properties can be only one of the following:
  "slideProperties": {
    object (SlideProperties)
  },
  "layoutProperties": {
    object (LayoutProperties)
  },
  "notesProperties": {
    object (NotesProperties)
  },
  "masterProperties": {
    object (MasterProperties)
  }
}

该形状将包含在此请求的response['pageElements']资源中,其格式为:

{
  "objectId": string,
  "size": {
    object (Size)
  },
  "transform": {
    object (AffineTransform)
  },
  "title": string,
  "description": string,

  // Union field element_kind can be only one of the following:
  "elementGroup": {
    object (Group)
  },
  "shape": {
    "shapeType": enum (Type),
    "text": {
      object (TextContent)
    },
    "shapeProperties": {
      object (ShapeProperties)
    },
    "placeholder": {
      object (Placeholder)
    }
  },
}

一旦从presentations.pages.get得到的响应中获得了Shape对象,就需要根据检索到的属性创建一个Page resource

{
  "objectId": string,
  "elementProperties": {
    object (PageElementProperties)
  },
  "shapeType": enum (Type)
}

还有一个CreateShapeRequest可用于删除上一张幻灯片上的Shape:

{
  "objectId": string
}

DeleteObjectRequestCreateShapeRequest都可以包含在同一batchUpdate请求中。请求正文应采用以下形式:

{
  "requests": [
    {
      object (Request)
    }
  ],
  "writeControl": {
    object (WriteControl)
  }
}

可以DeleteObjectRequest查看batchUpdate方法的完整文档。

我希望这对您有帮助!

参考文献: