loadWorkbook returns a workbook object conserving styles and formatting of the original .xlsx file.

loadWorkbook(file, xlsxFile = NULL, isUnzipped = FALSE)

Arguments

file

A path to an existing .xlsx or .xlsm file

xlsxFile

alias for file

isUnzipped

Set to TRUE if the xlsx file is already unzipped

Value

Workbook object.

See also

Author

Alexander Walker, Philipp Schauberger

Examples

## load existing workbook from package folder wb <- loadWorkbook(file = system.file("extdata", "loadExample.xlsx", package = "openxlsx")) names(wb) # list worksheets
#> [1] "IrisSample" "testing" "mtcars" "mtCars Pivot"
wb ## view object
#> A Workbook object. #> #> Worksheets: #> Sheet 1: "IrisSample" #> #> Custom row heights (row: height) #> 1: 34.5 #> Custom column widths (column: width) #> 1: 10.86, 2: 10.43, 3: 10.86, 4: 10.43, 5: 13.14, 7: 12.43, 8: 18.43, 9: 18.00, 10: 18.14, 11: 17.71, 12: 9.715 #> #> #> Sheet 2: "testing" #> #> Custom row heights (row: height) #> 7: 24, 8: 15.75, 20: 15.75, 27: 15.75, 28: 15.75, 29: 16.5, 31: 15.75, 33: 15.75, 35: 15.75, 36: 16.5, 37: 15.75, 38: 15.75 #> Custom column widths (column: width) #> 9: 13.00, 10: 13.00, 11: 13.00, 12: 13.00, 13: 13.00, 14: 13.00 #> #> #> Sheet 3: "mtcars" #> #> #> Sheet 4: "mtCars Pivot" #> #> Custom column widths (column: width) #> 1: 12.43, 2: 14.29, 3: 8.860, 4: 9.145, 5: 9.145 #> #> #> #> #> Images: #> Image 1: "/tmp/RtmpiEHpwa//file882c6a434982_openxlsx_loadWorkbook/xl/media/image2.jpeg" #> Image 2: "/tmp/RtmpiEHpwa//file882c6a434982_openxlsx_loadWorkbook/xl/media/image1.jpeg" #> #> Charts: #> Chart 1: "/tmp/RtmpiEHpwa//file882c6a434982_openxlsx_loadWorkbook/xl/charts/colors2.xml" #> Chart 2: "/tmp/RtmpiEHpwa//file882c6a434982_openxlsx_loadWorkbook/xl/charts/style2.xml" #> Chart 3: "/tmp/RtmpiEHpwa//file882c6a434982_openxlsx_loadWorkbook/xl/charts/chart2.xml" #> Chart 4: "/tmp/RtmpiEHpwa//file882c6a434982_openxlsx_loadWorkbook/xl/charts/chart1.xml" #> Chart 5: "/tmp/RtmpiEHpwa//file882c6a434982_openxlsx_loadWorkbook/xl/charts/style1.xml" #> Chart 6: "/tmp/RtmpiEHpwa//file882c6a434982_openxlsx_loadWorkbook/xl/charts/colors1.xml" #> Chart 7: "/tmp/RtmpiEHpwa//file882c6a434982_openxlsx_loadWorkbook/xl/charts/_rels/chart2.xml.rels" #> Chart 8: "/tmp/RtmpiEHpwa//file882c6a434982_openxlsx_loadWorkbook/xl/charts/_rels/chart1.xml.rels" #> Worksheet write order: 1, 2, 3, 4 #> Active Worksheet: 2
## Add a worksheet addWorksheet(wb, "A new worksheet") ## Save workbook if (FALSE) { saveWorkbook(wb, "loadExample.xlsx", overwrite = TRUE) }