Get/set order of worksheets in a Workbook object

worksheetOrder(wb)

worksheetOrder(wb) <- value

Arguments

wb

A workbook object

value

Vector specifying order to write worksheets to file

Details

This function does not reorder the worksheets within the workbook object, it simply shuffles the order when writing to file.

Examples

## setup a workbook with 3 worksheets
wb <- createWorkbook()
addWorksheet(wb = wb, sheetName = "Sheet 1", gridLines = FALSE)
writeDataTable(wb = wb, sheet = 1, x = iris)

addWorksheet(wb = wb, sheetName = "mtcars (Sheet 2)", gridLines = FALSE)
writeData(wb = wb, sheet = 2, x = mtcars)

addWorksheet(wb = wb, sheetName = "Sheet 3", gridLines = FALSE)
writeData(wb = wb, sheet = 3, x = Formaldehyde)

worksheetOrder(wb)
#> [1] 1 2 3
names(wb)
#> [1] "Sheet 1"          "mtcars (Sheet 2)" "Sheet 3"         
worksheetOrder(wb) <- c(1, 3, 2) # switch position of sheets 2 & 3
writeData(wb, 2, 'This is still the "mtcars" worksheet', startCol = 15)
worksheetOrder(wb)
#> [1] 1 3 2
names(wb) ## ordering within workbook is not changed
#> [1] "Sheet 1"          "mtcars (Sheet 2)" "Sheet 3"         
if (FALSE) { # \dontrun{
saveWorkbook(wb, "worksheetOrderExample.xlsx", overwrite = TRUE)
} # }
worksheetOrder(wb) <- c(3, 2, 1)
if (FALSE) { # \dontrun{
saveWorkbook(wb, "worksheetOrderExample2.xlsx", overwrite = TRUE)
} # }