tests/testthat/test-cloneWorksheet.R

context("clone Worksheet")


test_that("clone Worksheet with data", {
  wb <- createWorkbook()
  addWorksheet(wb, "Sheet 1")
  writeData(wb, "Sheet 1", 1)
  cloneWorksheet(wb, "Sheet 2", clonedSheet = "Sheet 1")


  file_name <- system.file("extdata", "cloneWorksheetExample.xlsx", package = "openxlsx")
  refwb <- loadWorkbook(file = file_name)

  expect_equal(sheets(wb), sheets(refwb))
  expect_equal(worksheetOrder(wb), worksheetOrder(refwb))
})

test_that("clone empty Worksheet", {
  wb <- createWorkbook()
  addWorksheet(wb, "Sheet 1")

  cloneWorksheet(wb, "Sheet 2", clonedSheet = "Sheet 1")


  file_name <- system.file("extdata", "cloneEmptyWorksheetExample.xlsx", package = "openxlsx")
  refwb <- loadWorkbook(file = file_name)

  expect_equal(sheets(wb), sheets(refwb))
  expect_equal(worksheetOrder(wb), worksheetOrder(refwb))
})

Try the openxlsx package in your browser

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

openxlsx documentation built on Sept. 20, 2024, 5:08 p.m.