Skip to Content
ClassesFOverGridImage

类: FOverGridImage

继承

  • FBase

方法

getId()

getId(): string

Get the id of the image

返回

string

The id of the image

示例

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const images = fWorksheet.getImages(); images.forEach((image) => { console.log(image, image.getId()); });

getType()

getType(): DrawingTypeEnum

Get the drawing type of the image

返回

DrawingTypeEnum

The drawing type of the image

示例

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const images = fWorksheet.getImages(); images.forEach((image) => { console.log(image, image.getType()); });

remove()

remove(): boolean

Remove the image from the sheet

返回

boolean

true if the image is removed successfully, otherwise false

示例

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const image = fWorksheet.getImages()[0]; const result = image?.remove(); console.log(result);

setBack()

setBack(): boolean

Move the image layer to the bottom layer

返回

boolean

success or not

示例

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const image = fWorksheet.getImages()[0]; const result = image?.setBack(); console.log(result);

setBackward()

setBackward(): boolean

Move the image layer backward by one level

返回

boolean

success or not

示例

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const image = fWorksheet.getImages()[0]; const result = image?.setBackward(); console.log(result);

setCrop()

setCrop( top?, left?, bottom?, right?): boolean

Set the cropping region of the image by defining the top, bottom, left, and right edges, thereby displaying the specific part of the image you want.

参数

参数类型描述
top?numberThe number of pixels to crop from the top of the image
left?numberThe number of pixels to crop from the left side of the image
bottom?numberThe number of pixels to crop from the bottom of the image
right?numberThe number of pixels to crop from the right side of the image

返回

boolean

true if the crop is set successfully, otherwise false

示例

// set the crop of the image, top 10px, left 10px, bottom 10px, right 10px. const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const image = fWorksheet.getImages()[0]; const result = image?.setCrop(10, 10, 10, 10); console.log(result);

setForward()

setForward(): boolean

Move the image layer forward by one level

返回

boolean

true if the image is moved forward successfully, otherwise false

示例

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const image = fWorksheet.getImages()[0]; const result = image?.setForward(); console.log(result);

setFront()

setFront(): boolean

Move the image layer to the top layer

返回

boolean

success or not

示例

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const image = fWorksheet.getImages()[0]; const result = image?.setFront(); console.log(result);

setPositionAsync()

调用签名

setPositionAsync(row, column): Promise<boolean>

Set the position of the image

参数
参数类型描述
rownumberThe row index of the image start position
columnnumberThe column index of the image start position
返回

Promise<boolean>

true if the position is set successfully, otherwise false

示例
// set the position of the image, the start position is F6 cell. const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const image = fWorksheet.getImages()[0]; const result = image?.setPositionAsync(5, 5); console.log(result);

调用签名

setPositionAsync( row, column, rowOffset?, columnOffset?): Promise<boolean>
参数
参数类型描述
rownumberThe row index of the image start position
columnnumberThe column index of the image start position
rowOffset?numberThe row offset of the image start position, pixel unit
columnOffset?numberThe column offset of the image start position, pixel unit
返回

Promise<boolean>

true if the position is set successfully, otherwise false

示例
// set the position of the image, the start position is F6 cell, and the offset is 10px. const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const image = fWorksheet.getImages()[0]; const result = image?.setPositionAsync(5, 5, 10, 10); console.log(result);

setRotate()

setRotate(angle): boolean

Set the rotation angle of the image

参数

参数类型描述
anglenumberDegree of rotation of the image, for example, 90, 180, 270, etc.

返回

boolean

true if the rotation is set successfully, otherwise false

示例

// set 90 degrees rotation of the image const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const image = fWorksheet.getImages()[0]; const result = image?.setRotate(90); console.log(result);

setSizeAsync()

setSizeAsync(width, height): Promise<boolean>

Set the size of the image

参数

参数类型描述
widthnumberThe width of the image, pixel unit
heightnumberThe height of the image, pixel unit

返回

Promise<boolean>

true if the size is set successfully, otherwise false

示例

// set the image width 120px and height 50px const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const image = fWorksheet.getImages()[0]; const result = image?.setSizeAsync(120, 50); console.log(result);

setSource()

调用签名

setSource(source): boolean

Set the source of the image

参数
参数类型描述
sourcestringThe source of the image
返回

boolean

true if the source is set successfully, otherwise false

示例
const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const image = fWorksheet.getImages()[0]; const result = image?.setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4'); console.log(result);

调用签名

setSource(source, sourceType?): boolean

Set the source of the image, change image display.

参数
参数类型描述
sourcestringThe source of the image
sourceType?ImageSourceTypeThe source type of the image, default is URL
返回

boolean

true if the source is set successfully, otherwise false

示例
const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const image = fWorksheet.getImages()[0]; const result = image?.setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL); console.log(result);

toBuilder()

toBuilder(): FOverGridImageBuilder

Convert the image to a FOverGridImageBuilder

返回

FOverGridImageBuilder

The builder FOverGridImageBuilder

示例

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const images = fWorksheet.getImages(); images.forEach((image) => { console.log(image, image.toBuilder().getSource()); });