Learn R Programming

openxlsx2 (version 0.8)

wb_merge_cells: Worksheet cell merging

Description

Merge cells within a worksheet

Usage

wb_merge_cells(wb, sheet = current_sheet(), dims = NULL, ...)

wb_unmerge_cells(wb, sheet = current_sheet(), dims = NULL, ...)

Arguments

wb

A workbook object

sheet

A name or index of a worksheet

dims

worksheet cells

...

additional arguments

Details

As merged region must be rectangular, only min and max of cols and rows are used.

See Also

Other workbook wrappers: wb_add_chartsheet(), wb_add_data_table(), wb_add_data(), wb_add_formula(), wb_add_pivot_table(), wb_add_worksheet(), wb_base_font, wb_clone_worksheet(), wb_col_widths, wb_copy_cells(), wb_creators, wb_freeze_pane(), wb_grouping, wb_save(), wb_set_last_modified_by(), wb_set_row_heights(), wb_workbook()

Examples

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

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

# Merge cells: Row 2 column C to F (3:6)
wb <- wb_merge_cells(wb, "Sheet 1", cols = 2, rows = 3:6)

# Merge cells:Rows 10 to 20 columns A to J (1:10)
wb <- wb_merge_cells(wb, 1, cols = 1:10, rows = 10:20)

# Intersecting merges
wb <- wb_merge_cells(wb, 2, cols = 1:10, rows = 1)
wb <- wb_merge_cells(wb, 2, cols = 5:10, rows = 2)
wb <- wb_merge_cells(wb, 2, cols = c(1, 10), rows = 12) # equivalent to 1:10
try(wb_merge_cells(wb, 2, cols = 1, rows = c(1,10)))    # intersects existing merge

# remove merged cells
wb <- wb_unmerge_cells(wb, 2, cols = 1, rows = 1)  # removes any intersecting merges
wb <- wb_merge_cells(wb, 2, cols = 1, rows = 1:10) # Now this works

Run the code above in your browser using DataLab