Skip to content

jx:image

jx:image inserts an image from byte data into the specified cell area. Use it for employee photos, company logos, product images, chart screenshots, or any visual content.

jx:image(src="employee.Photo" imageType="PNG" lastCell="C5")
AttributeDescriptionDefaultRequired
srcExpression for image bytes ([]byte)Yes
imageTypeFormat: PNG, JPEG, GIF, etc.Yes
lastCellBottom-right cell defining the image areaYes
scaleXHorizontal scale factor1.0No
scaleYVertical scale factor1.0No
logoBytes, _ := os.ReadFile("logo.png")
data := map[string]any{
"company": map[string]any{
"Name": "Acme Corp",
"Logo": logoBytes,
},
}

Template cell A1 comment:

jx:image(src="company.Logo" imageType="PNG" lastCell="C3")

The image fills the A1:C3 area. The cell dimensions control the image size.

Adjust the image size relative to the cell area:

jx:image(src="logo" imageType="PNG" scaleX="0.5" scaleY="0.5" lastCell="B2")

Combine with jx:each for a different image per row — employee photos, product thumbnails, etc.:

Cell A1 comment:
jx:area(lastCell="D3")
jx:each(items="employees" var="e" lastCell="D3")
Cell A1 also has:
jx:image(src="e.Photo" imageType="JPEG" lastCell="A3")

Each employee gets their photo in column A, with name/details in columns B-D.

  • imageType must match the actual bytes. Setting imageType="PNG" on a JPEG file produces a corrupted image. Sniff the format if your data is mixed: PNG starts with 89 50 4E 47, JPEG with FF D8 FF.
  • The cell area determines image size — but only loosely. Excel anchors the image to the top-left cell; resizing the cell after the fact rescales the image. Use scaleX/scaleY if you need a different rendered size than the area suggests.
  • Empty []byte → blank cell. XLFill silently skips zero-length image data rather than erroring. Validate your byte slice before passing it.
  • Streaming mode rejects images. Adding an image on a streamed sheet returns an error. Use sequential mode or WithStreamingSheets to exclude the image sheet.

Download the runnable example: template t10.xlsx | output 10_image.xlsx | code snippet

Need to merge cells for section headers?

jx:mergeCells →