Learn R Programming

openxlsx2 (version 0.3.1)

create_comment: Create, write and remove comments

Description

The comment functions (create, write and remove) allow the modification of comments. In newer Excels they are called notes, while they are called comments in openxml. Modification of what Excel now calls comment (openxml calls them threadedComments) is not yet possible

Usage

create_comment(
  text,
  author = Sys.info()[["user"]],
  style = NULL,
  visible = TRUE,
  width = 2,
  height = 4
)

write_comment(wb, sheet, col, row, comment, xy = NULL)

remove_comment(wb, sheet, col, row, gridExpand = TRUE)

wb_add_comment( wb, sheet = current_sheet(), col, row, dims = rowcol_to_dims(row, col), comment )

wb_remove_comment( wb, sheet = current_sheet(), col, row, dims = rowcol_to_dims(row, col), gridExpand = TRUE )

Value

The wbWorkbook object

The wbWorkbook object

Arguments

text

Comment text. Character vector.

author

Author of comment. Character vector of length 1

style

A Style object or list of style objects the same length as comment vector.

visible

TRUE or FALSE. Is comment visible.

width

Textbox integer width in number of cells

height

Textbox integer height in number of cells

wb

A workbook object

sheet

A worksheet of the workbook

col

A column to apply the comment

row

A row to apply the comment

comment

A comment to apply to the worksheet

xy

An alternative to specifying col and row individually. A vector of the form c(col, row).

gridExpand

Remove all comments inside the grid. Similar to dims "A1:B2"

dims

Optional row and column as spreadsheet dimension, e.g. "A1"

Examples

Run this code
wb <- wb_workbook()
wb$add_worksheet("Sheet 1")

# write comment without author
c1 <- create_comment(text = "this is a comment", author = "")
write_comment(wb, 1, col = "B", row = 10, comment = c1)

# Write another comment with author information
c2 <- create_comment(text = "this is another comment", author = "Marco Polo")
write_comment(wb, 1, col = "C", row = 10, comment = c2)

# write a styled comment with system author
s1 <- create_font(b = "true", color = wb_colour(hex = "FFFF0000"), sz = "12")
s2 <- create_font(color = wb_colour(hex = "FF000000"), sz = "9")
c3 <- create_comment(text = c("This Part Bold red\n\n", "This part black"), style = c(s1, s2))

write_comment(wb, 1, col = 6, row = 3, comment = c3)

# remove the first comment
remove_comment(wb, 1, col = "B", row = 10)

Run the code above in your browser using DataLab