tests/testthat/test-xlsx.R

test_that("create and manipulate sheet", {
  doc <- read_xlsx()
  doc <- add_sheet(doc, label = "sheet1")
  doc <- sheet_select(doc, sheet = "sheet1")

  expect_true("sheet1" %in% doc$worksheets$sheet_names())

  xml_sheets <- list.files(file.path(doc$package_dir, "xl", "worksheets"),
    pattern = "\\.xml$"
  )
  expect_equal(length(doc), 2)
  expect_equal(xml_sheets, c("sheet1.xml", "sheet2.xml"))

  sheet_id <- doc$worksheets$get_sheet_id("sheet1")
  wb_view <- xml_find_first(doc$worksheets$get(), "d1:bookViews/d1:workbookView")
  expect_equal(as.integer(xml_attr(wb_view, "activeTab")), sheet_id - 1)
})

Try the officer package in your browser

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

officer documentation built on Oct. 10, 2024, 1:06 a.m.