wb_load returns a workbook object conserving styles and formatting of the original .xlsx file.
wb_load(file, xlsxFile = NULL, sheet, data_only = FALSE, calc_chain = FALSE)
A path to an existing .xlsx or .xlsm file
alias for file
optional sheet parameter. if this is applied, only the selected sheet will be loaded.
mode to import if only a data frame should be returned. This strips the wbWorkbook to a bare minimum.
optionally you can keep the calculation chain intact. This is used by spreadsheet software to identify the order in which formulas are evaluated. Removing the calculation chain is considered harmless. The calc chain will be created upon the next time the worksheet is loaded in spreadsheet software. Keeping it, might only speed loading time in said software.
Workbook object.
A warning is displayed if an xml namespace for main is found in the
xlsx file. Certain xlsx files created by third-party applications contain a
namespace (usually x
). This namespace is not required for the file to work
in spreadsheet software and is not expected by openxlsx2
. Therefore it is
removed when the file is loaded into a workbook. Removal is generally
expected to be safe, but the feature is still experimental.
## load existing workbook from package folder
wb <- wb_load(file = system.file("extdata", "loadExample.xlsx", package = "openxlsx2"))
wb$get_sheet_names() # list worksheets
#> IrisSample testing mtcars mtCars Pivot
#> "IrisSample" "testing" "mtcars" "mtCars Pivot"
wb ## view object
#> A Workbook object.
#>
#> Worksheets:
#> Sheets: IrisSample testing mtcars mtCars Pivot
#> Write order: 1, 2, 3, 4
## Add a worksheet
wb$add_worksheet("A new worksheet")