google-slides-api - 是否可以将形状从幻灯片移动到另一个?
问题描述
我在 NodeJS 服务器上使用 Google Slides API 来编辑演示文稿,但我在文档中找不到任何关于将对象移动到另一张幻灯片的内容,例如 Shape。
解决方案
回答:
您必须通过从 的响应中获取形状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
请求中。请求正文应采用以下形式:CreateShapeRequest
batchUpdate
{
"requests": [
{
object (Request)
}
],
"writeControl": {
object (WriteControl)
}
}
batchUpdate
可以在此处查看该方法的完整文档。
参考:
推荐阅读
- python - SQLAlchemy 查询父级的多个子级返回 [(bool, bool)]
- python - Django - 在模板中打印字典的长度
- swift - 匹配“com.project.name”,但不匹配包含其他内容
- reactjs - Reactjs 将 Select 标签连接到 ToggleButton
- c - GWL_WNDPROC 未声明
- python-2.7 - 如何使用flask和python从html中的链接创建指向存储在内存中的动态文件的链接?
- java - Eclipse IDE 在 JPA 中显示复合主键类的错误
- javascript - 带有绝对路径的故事书
- ssl - Xamarin - Android - 手动验证服务器的 SSL 证书 ModernHttpClient
- matlab - 只希望 Matlab 中 pca 的分数和潜在值以节省内存