修复了锚定在 Paragraph
上的位置图片。与 InlineImage
不同,PositionedImage
不是 Element
。它没有父级或同级 Element
。相反,它会锚定到 Paragraph
或 ListItem
,并通过相对于该锚点的偏移放置。PositionedImage
具有可用于引用它的 ID。
var body = DocumentApp.getActiveDocument().getBody(); // Append a new paragraph. var paragraph = body.appendParagraph("New paragraph to anchor the image to."); * // Get an image in Drive from its ID. var image = DriveApp.getFileById('ENTER_IMAGE_FILE_ID_HERE').getBlob(); // Add the PositionedImage with offsets (in points). var posImage = paragraph.addPositionedImage(image) .setTopOffset(60) .setLeftOffset(40);
方法
方法 | 返回类型 | 简介 |
---|---|---|
getAs(contentType) | Blob | 以转换为指定内容类型的 blob 形式返回此对象中的数据。 |
getBlob() | Blob | 以 blob 的形式返回此对象中的数据。 |
getHeight() | Integer | 检索图片的高度(以像素为单位)。 |
getId() | String | 获取图片的 ID。 |
getLayout() | PositionedLayout | 获取表示图片的布局方式的枚举值。 |
getLeftOffset() | Number | 获取图片相对于段落左边缘的偏移量(以点为单位)。 |
getParagraph() | Paragraph | 获取图片锚定到的 Paragraph 。 |
getTopOffset() | Number | 获取图片相对于段落顶部的偏移量(以点为单位)。 |
getWidth() | Integer | 检索图片的宽度(以像素为单位)。 |
setHeight(height) | PositionedImage | 设置图片的高度(以像素为单位)。 |
setLayout(layout) | PositionedImage | 设置图片布局方式的定义。 |
setLeftOffset(offset) | PositionedImage | 设置图片相对于段落左边缘的偏移量(以点为单位)。 |
setTopOffset(offset) | PositionedImage | 设置图片相对于段落顶部的偏移量(以点为单位)。 |
setWidth(width) | PositionedImage | 设置图片的宽度(以像素为单位)。 |
详细文档
getAs(contentType)
以转换为指定内容类型的 blob 形式返回此对象中的数据。此方法会在文件名中添加适当的扩展名,例如 "myfile.pdf"。但是,它假定文件名中最后一个句号后面的部分(如果有)是应替换的现有扩展名。因此,“ShoppingList.12.25.2014”将变为“ShoppingList.12.25.pdf”。
如需查看转化的每日配额,请参阅 Google 服务的配额。新创建的 Google Workspace 网域可能暂时受到更严格的配额约束。
参数
名称 | 类型 | 说明 |
---|---|---|
contentType | String | 要转换为的 MIME 类型。对于大多数 blob,'application/pdf' 是唯一有效的选项。对于 BMP、GIF、JPEG 或 PNG 格式的图片,'image/bmp' 、'image/gif' 、'image/jpeg' 或 'image/png' 中的任意一种都有效。 |
返回
Blob
- 数据作为 blob。
getBlob()
getHeight()
检索图片的高度(以像素为单位)。
返回
Integer
- 图片的高度(以像素为单位)
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getId()
获取图片的 ID。
返回
String
- 映像 ID
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getLayout()
获取表示图片的布局方式的枚举值。
返回
PositionedLayout
- 图片布局
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getLeftOffset()
获取图片相对于段落左边缘的偏移量(以点为单位)。
返回
Number
- 图片相对于左侧段落的偏移量
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getParagraph()
getTopOffset()
获取图片相对于段落顶部的偏移量(以点为单位)。
返回
Number
- 图片距离左侧段落顶部
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getWidth()
检索图片的宽度(以像素为单位)。
返回
Integer
- 图片的宽度(以像素为单位)
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setHeight(height)
设置图片的高度(以像素为单位)。
参数
名称 | 类型 | 说明 |
---|---|---|
height | Integer | 图片的高度(以像素为单位) |
返回
PositionedImage
- 当前对象
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setLayout(layout)
设置图片布局方式的定义。
参数
名称 | 类型 | 说明 |
---|---|---|
layout | PositionedLayout | 表示布局模式的枚举 |
返回
PositionedImage
- 此对象用于串联
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setLeftOffset(offset)
设置图片相对于段落左边缘的偏移量(以点为单位)。
参数
名称 | 类型 | 说明 |
---|---|---|
offset | Number | 相对于段落左边缘的偏移量 |
返回
PositionedImage
- 此对象用于串联
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setTopOffset(offset)
设置图片相对于段落顶部的偏移量(以点为单位)。
参数
名称 | 类型 | 说明 |
---|---|---|
offset | Number | 相对于段落上边缘的偏移量 |
返回
PositionedImage
- 此对象用于串联
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setWidth(width)
设置图片的宽度(以像素为单位)。
参数
名称 | 类型 | 说明 |
---|---|---|
width | Integer | 图片的宽度(以像素为单位) |
返回
PositionedImage
- 当前对象
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents