Skip to Content
ClassesFOverGridImage

Class: FOverGridImage

Extends

  • FBase

Methods

getId()

getId(): string

Get the id of the image

Returns

string

The id of the image

Example

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

Returns

DrawingTypeEnum

The drawing type of the image

Example

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

Returns

boolean

true if the image is removed successfully, otherwise false

Example

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

Returns

boolean

true if the image is moved to the bottom layer successfully, otherwise false

Example

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

Returns

boolean

true if the image is moved backward successfully, otherwise false

Example

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.

Parameters

ParameterTypeDescription
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

Returns

boolean

true if the crop is set successfully, otherwise false

Example

// 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

Returns

boolean

true if the image is moved forward successfully, otherwise false

Example

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

Returns

boolean

true if the image is moved to the top layer successfully, otherwise false

Example

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

setPositionAsync()

Call Signature

setPositionAsync(row, column): Promise<boolean>

Set the position of the image

Parameters
ParameterTypeDescription
rownumberThe row index of the image start position
columnnumberThe column index of the image start position
Returns

Promise<boolean>

true if the position is set successfully, otherwise false

Example
// 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);

Call Signature

setPositionAsync( row, column, rowOffset?, columnOffset?): Promise<boolean>
Parameters
ParameterTypeDescription
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
Returns

Promise<boolean>

true if the position is set successfully, otherwise false

Example
// 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

Parameters

ParameterTypeDescription
anglenumberDegree of rotation of the image, for example, 90, 180, 270, etc.

Returns

boolean

true if the rotation is set successfully, otherwise false

Example

// 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

Parameters

ParameterTypeDescription
widthnumberThe width of the image, pixel unit
heightnumberThe height of the image, pixel unit

Returns

Promise<boolean>

true if the size is set successfully, otherwise false

Example

// 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()

Call Signature

setSource(source): boolean

Set the source of the image

Parameters
ParameterTypeDescription
sourcestringThe source of the image
Returns

boolean

true if the source is set successfully, otherwise false

Example
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);

Call Signature

setSource(source, sourceType?): boolean

Set the source of the image, change image display.

Parameters
ParameterTypeDescription
sourcestringThe source of the image
sourceType?ImageSourceTypeThe source type of the image, default is URL
Returns

boolean

true if the source is set successfully, otherwise false

Example
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

Returns

FOverGridImageBuilder

The builder FOverGridImageBuilder

Example

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