tests/testthat/test.workbook.getActiveSheetIndex.R

test_that("Tests around querying the active sheet index of an Excel workbook", {
  # Create workbooks
  wb.xls <- loadWorkbook("resources/testWorkbookActiveSheetIndexAndName.xls", create = FALSE)
  wb.xlsx <- loadWorkbook("resources/testWorkbookActiveSheetIndexAndName.xlsx", create = FALSE)

  # Check that the active sheet index is 5 (*.xls)
  expect_true(getActiveSheetIndex(wb.xls) == 5)

  # Check that the active sheet index is 5 (*.xlsx)
  expect_true(getActiveSheetIndex(wb.xlsx) == 5)
})

Try the XLConnect package in your browser

Any scripts or data that you put into this service are public.

XLConnect documentation built on Feb. 24, 2026, 9:06 a.m.