Learn R Programming

openxlsx2 (version 0.6.1)

wb_add_image: Insert an image into a worksheet

Description

Insert an image into a worksheet

Usage

wb_add_image(
  wb,
  sheet = current_sheet(),
  file,
  width = 6,
  height = 3,
  startRow = 1,
  startCol = 1,
  rowOffset = 0,
  colOffset = 0,
  units = "in",
  dpi = 300,
  dims = rowcol_to_dim(startRow, startCol)
)

Arguments

wb

A workbook object

sheet

A name or index of a worksheet

file

An image file. Valid file types are: "jpeg", "png", "bmp"

width

Width of figure.

height

Height of figure.

startRow

Row coordinate of upper left corner of the image

startCol

Column coordinate of upper left corner of the image

rowOffset

offset vector for one or two cell anchor within cell (row)

colOffset

offset vector for one or two cell anchor within cell (column)

units

Units of width and height. Can be "in", "cm" or "px"

dpi

Image resolution used for conversion between units.

dims

Dimensions where to plot. Default absolute anchor, single cell (eg. "A1") oneCellAnchor, cell range (eg. "A1:D4") twoCellAnchor

See Also

wb_add_plot()

Examples

Run this code
## Create a new workbook
wb <- wb_workbook("Ayanami")

## Add some worksheets
wb$add_worksheet("Sheet 1")
wb$add_worksheet("Sheet 2")
wb$add_worksheet("Sheet 3")

## Insert images
img <- system.file("extdata", "einstein.jpg", package = "openxlsx2")
wb$add_image("Sheet 1", img, startRow = 5, startCol = 3, width = 6, height = 5)
wb$add_image(2, img, startRow = 2, startCol = 2)
wb$add_image(3, img, width = 15, height = 12, startRow = 3, startCol = "G", units = "cm")

Run the code above in your browser using DataLab