FOverGridImage

GitHubEdit on GitHub
packages@univerjs/sheets-drawing-ui

APIs

getId

Get the id of the image

Signature

getId(): string

Returns

  • (string) — The id of the image

Examples

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

getType

Get the drawing type of the image

Signature

getType(): DrawingTypeEnum

Returns

  • (DrawingTypeEnum) — The drawing type of the image

Examples

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

remove

Remove the image from the sheet

Signature

remove(): boolean

Returns

  • (boolean) — true if the image is removed successfully, otherwise false

Examples

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

setBack

Move the image layer to the bottom layer

Signature

setBack(): boolean

Returns

  • (boolean) — true if the image is moved to the bottom layer successfully, otherwise false

Examples

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

setBackward

Move the image layer backward by one level

Signature

setBackward(): boolean

Returns

  • (boolean) — true if the image is moved backward successfully, otherwise false

Examples

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

setCrop

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.

Signature

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

Parameters

  • top (number) — - The number of pixels to crop from the top of the image
  • left (number) — - The number of pixels to crop from the left side of the image
  • bottom (number) — - The number of pixels to crop from the bottom of the image
  • right (number) — - The number of pixels to crop from the right side of the image

Returns

  • (boolean) — true if the crop is set successfully, otherwise false

Examples

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

Move the image layer forward by one level

Signature

setForward(): boolean

Returns

  • (boolean) — true if the image is moved forward successfully, otherwise false

Examples

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

setFront

Move the image layer to the top layer

Signature

setFront(): boolean

Returns

  • (boolean) — true if the image is moved to the top layer successfully, otherwise false

Examples

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

setPositionAsync

Signature

setPositionAsync(row: number, column: number, rowOffset?: number, columnOffset?: number): Promise<boolean>

setRotate

Set the rotation angle of the image

Signature

setRotate(angle: number): boolean

Parameters

  • angle (number) — - Degree of rotation of the image, for example, 90, 180, 270, etc.

Returns

  • (boolean) — true if the rotation is set successfully, otherwise false

Examples

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

Set the size of the image

Signature

setSizeAsync(width: number, height: number): Promise<boolean>

Parameters

  • width (number) — - The width of the image, pixel unit
  • height (number) — - The height of the image, pixel unit

Returns

  • (Promise<boolean>) — true if the size is set successfully, otherwise false

Examples

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

Signature

setSource(source: string, sourceType?: ImageSourceType): boolean

toBuilder

Convert the image to a FOverGridImageBuilder

Signature

toBuilder(): FOverGridImageBuilder

Returns

  • (FOverGridImageBuilder) — The builder FOverGridImageBuilder

Examples

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