首页 > 解决方案 > 是否可以将形状从幻灯片移动到另一个?

问题描述

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

标签: google-slides-api

解决方案


回答:

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

更多信息:

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

首先,您需要发出请求以presentations.pages.get获取PageElement页面中的所有对象。根据文档,Shape 是PageElement表示幻灯片上形状的对象的一个​​实例。

的响应presentations.pages.get将是一个Page资源

{
  "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)
  }
}

Shape 将包含在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)
    }
  },
}

从您获得的响应中获得 Shape 对象后presentations.pages.get,您将需要CreateShapeRequest从检索到的属性中创建一个:

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

还有一个DeleteObjectRequest可以用来删除上一张幻灯片上的形状:

{
  "objectId": string
}

和可以同时包含在同一个DeleteObjectRequest请求中。请求正文应采用以下形式:CreateShapeRequestbatchUpdate

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

batchUpdate可以在此处查看该方法的完整文档。

参考:


推荐阅读