Shapes
Shapes
JSSDK: 1.3.1、zOffice V6.0 FP1 支持
Shape 对象的集合,这些对象表示文档中的所有形状。 每个 Shape 对象都代表绘图层中的一个对象,如自选图形、任意多边形、OLE 对象或图片。(目前仅支持浮动图片)
属性
count
返回一个 Long ,该值代表集合中图形的数量。 此为只读属性。
语法
Application.ActiveDocument.Shapes.count
Application: 文档类型应用对象
返回值
Promise<number>
示例
async function example() {
const count = await Application.ActiveDocument.Shapes.count;
}
方法
addPicture
在绘图画布上添加一幅图片,返回一个 Shape 对象(默认添加到当前光标位置)
语法
Application.ActiveDocument.Shapes.addPicture(file, left, top, width, height, range, wdWrapType)
Application: 文档类型应用对象
参数
| 属性 | 数据类型 | 必填 | 说明 |
|---|---|---|---|
| file | File | 是 | 图片的文件对象(限10MB)。 |
| left | number | 否 | 新图片的左边缘相对于绘图画布的位置,以磅为单位。(暂不支持) |
| top | number | 否 | 新图片的上边缘相对于绘图画布的位置,以磅为单位。(暂不支持) |
| width | number | 否 | 图片的宽度,以磅为单位。 |
| height | number | 否 | 图片的高度,以磅为单位。 |
| range | Word.Range | 否 | 指定插入图片的区域。(默认在当前选区添加) |
| wrapType | Word.WdWrapType | 否 | 环绕类型,默认为将图片放在文字前面。 |
返回值
Promise<Word.Shape>
示例
<input type="file" name="插入非嵌入式图片" id="imageInput"/>
const inputElement = document.getElementById('imageInput');
// sample1,在当前选区添加图片
inputElement.onchange = async function(width, height, wrapType) {
const shapes = await Application.ActiveDocument.Shapes;
const shape = await shapes.addPicture(inputElement.files[0], undefined, undefined, width, height, undefined, wrapType);
}
// sample2,在指定区域添加图片
inputElement.onchange = async function(width, height, wrapType) {
const shapes = await Application.ActiveDocument.Shapes;
const pm = await Application.ActiveDocument.PermMarks.item(1);
const pmRange = await pm.range;
const shape = await shapes.addPicture(inputElement.files[0], undefined, undefined, width, height, range, wrapType);
}
item
返回集合中的单个 Shape 对象。
语法
Application.ActiveDocument.Shapes.item(key)
Application: 文档类型应用对象
参数
| 属性 | 数据类型 | 必填 | 说明 |
|---|---|---|---|
| key | number | string | 是 | Shape 在文档中的序号(从1开始)或者其名称 |
返回值
Promise<Word.Shape>
示例
async function example() {
const Shapes = await Application.ActiveDocument.Shapes;
const shape = await Shapes.item(1);
}
async function example() {
const Shapes = await Application.ActiveDocument.Shapes;
const shape = await Shapes.item('签章图片.png');
}