wb_clone_worksheet {openxlsx2} | R Documentation |
Create copies of a worksheet within a workbook
Description
Create a copy of a worksheet in the same wbWorkbook
object.
Cloning is possible only to a limited extent. References to sheet names in formulas, charts, pivot tables, etc. may not be updated. Some elements like named ranges and slicers cannot be cloned yet.
Cloning from another workbook is still an experimental feature and might not work reliably. Cloning data, media, charts and tables should work. Slicers and pivot tables as well as everything everything relying on dxfs styles (e.g. custom table styles and conditional formatting) is currently not implemented. Formula references are not updated to reflect interactions between workbooks.
Usage
wb_clone_worksheet(wb, old = current_sheet(), new = next_sheet(), from = NULL)
Arguments
wb |
A |
old |
Name of existing worksheet to copy |
new |
Name of the new worksheet to create |
from |
(optional) Workbook to clone old from |
Value
The wbWorkbook
object, invisibly.
See Also
Other workbook wrappers:
base_font-wb
,
col_widths-wb
,
creators-wb
,
grouping-wb
,
row_heights-wb
,
wb_add_chartsheet()
,
wb_add_data()
,
wb_add_data_table()
,
wb_add_formula()
,
wb_add_pivot_table()
,
wb_add_slicer()
,
wb_add_worksheet()
,
wb_base_colors
,
wb_copy_cells()
,
wb_freeze_pane()
,
wb_merge_cells()
,
wb_save()
,
wb_set_last_modified_by()
,
wb_workbook()
Examples
# Create a new workbook
wb <- wb_workbook()
# Add worksheets
wb$add_worksheet("Sheet 1")
wb$clone_worksheet("Sheet 1", new = "Sheet 2")
# Take advantage of waiver functions
wb$clone_worksheet(old = "Sheet 1")
## cloning from another workbook
# create a workbook
wb <- wb_workbook()$
add_worksheet("NOT_SUM")$
add_data(x = head(iris))$
add_fill(dims = "A1:B2", color = wb_color("yellow"))$
add_border(dims = "B2:C3")
# we will clone this styled chart into another workbook
fl <- system.file("extdata", "oxlsx2_sheet.xlsx", package = "openxlsx2")
wb_from <- wb_load(fl)
# clone styles and shared strings
wb$clone_worksheet(old = "SUM", new = "SUM", from = wb_from)