Learn R Programming

openxlsx2 (version 1.4)

wb_add_image: Insert an image into a worksheet

Description

Insert an image into a worksheet

Usage

wb_add_image(
  wb,
  sheet = current_sheet(),
  dims = "A1",
  file,
  width = 6,
  height = 3,
  row_offset = 0,
  col_offset = 0,
  units = "in",
  dpi = 300,
  ...
)

Arguments

wb

A workbook object

sheet

A name or index of a worksheet

dims

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

file

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

width

Width of figure.

height

Height of figure.

row_offset

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

col_offset

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.

...

additional arguments

See Also

wb_add_chart_xml() wb_add_drawing() wb_add_mschart() wb_add_plot()

Examples

Run this code
img <- system.file("extdata", "einstein.jpg", package = "openxlsx2")

wb <- wb_workbook()$
  add_worksheet()$
  add_image("Sheet 1", dims = "C5", file = img, width = 6, height = 5)$
  add_worksheet()$
  add_image(dims = "B2", file = img)$
  add_worksheet()$
  add_image(dims = "G3", file = img, width = 15, height = 12, units = "cm")

Run the code above in your browser using DataLab