1
2context("Styles")
3
4test_that("setStyle", {
5
6  tmp_file <- temp_xlsx()
7
8  # lorem ipsum
9  txt <- paste0(
10    "Lorem ipsum dolor sit amet, consectetur adipiscing elit, ",
11    "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ",
12    "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris",
13    "nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in ",
14    "reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla",
15    "pariatur. Excepteur sint occaecat cupidatat non proident, sunt in ",
16    "culpa qui officia deserunt mollit anim id est laborum."
17  )
18
19  ## create workbook
20  wb <- createWorkbook()
21  addWorksheet(wb, "Test")
22  writeData(wb, "Test", txt)
23
24  ## create a style
25  s <- createStyle(
26    fontSize = 12,
27    fontColour = "black",
28    valign="center",
29    wrapText = TRUE,
30    halign = "justify"
31  )
32  addStyle(wb, "Test", s, 1, 1)
33  setColWidths(wb, "Test", 1, 50)
34  setRowHeights(wb, "Test", 1, 150)
35
36  ## save workbook
37  saveWorkbook(wb, tmp_file)
38
39  ## load it again
40  wb2 <- loadWorkbook(tmp_file)
41  s2 <- getStyles(wb2)[[1]]
42
43  ## test that the style survived the round trip
44  expect_equal(s2$fontSize, c(val="12"))
45  expect_equal(s2$fontColour, c(rgb="FF000000"))
46  expect_equal(s2$valign, "center")
47  expect_equal(s2$wrapText, TRUE)
48  expect_equal(s2$halign, "justify")
49
50})
51