【问题标题】:Is it possible to move a Shape from a slide to another?是否可以将形状从幻灯片移动到另一个?
【发布时间】:2020-09-11 11:31:41
【问题描述】:

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

【问题讨论】:

    标签: google-slides-api


    【解决方案1】:

    答案:

    您必须通过从presentations.pages.get 的响应中获取形状、删除它并使用presentations.batchUpdate 插入它来完成此操作。

    更多信息:

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

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

    presentations.pages.get 的响应将是 Page resource

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

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

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

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

    {
      "objectId": string
    }
    

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

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

    batchUpdate 方法的完整文档可见here

    参考资料:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-10
      • 1970-01-01
      • 1970-01-01
      • 2018-03-29
      • 1970-01-01
      • 1970-01-01
      • 2013-01-31
      • 1970-01-01
      相关资源
      最近更新 更多