Add a worksheet to a workbook

Description

Add a worksheet to a workbook

Usage

1
2
3
addWorksheet(wb, sheetName, gridLines = TRUE, tabColour = NULL,
  zoom = 100, header = NULL, footer = NULL, evenHeader = NULL,
  evenFooter = NULL, firstHeader = NULL, firstFooter = NULL)

Arguments

wb

A Workbook object to attach the new worksheet

sheetName

A name for the new worksheet

gridLines

A logical. If FALSE, the worksheet grid lines will be hidden.

tabColour

Colour of the worksheet tab. A valid colour (belonging to colours()) or a valid hex colour beginning with "#"

zoom

A numeric betwettn 10 and 400. Worksheet zoom level as a percentage.

header

document header. Character vector of length 3 corresponding to positons left, center, right. Use NA to skip a positon.

footer

document footer. Character vector of length 3 corresponding to positons left, center, right. Use NA to skip a positon.

evenHeader

document header for even pages.

evenFooter

document footer for even pages.

firstHeader

document header for first page only.

firstFooter

document footer for first page only.

Details

Headers and footers can contain special tags

  • &[Page] Page number

  • &[Pages] Number of pages

  • &[Date] Current date

  • &[Time] Current time

  • &[Path] File path

  • &[File] File name

  • &[Tab] Worksheet name

Value

XML tree

Author(s)

Alexander Walker

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
## Create a new workbook
wb <- createWorkbook("Fred")

## Add 3 worksheets
addWorksheet(wb, "Sheet 1")
addWorksheet(wb, "Sheet 2", gridLines = FALSE)
addWorksheet(wb, "Sheet 3", tabColour = "red")
addWorksheet(wb, "Sheet 4", gridLines = FALSE, tabColour = "#4F81BD")

## Headers and Footers
addWorksheet(wb, "Sheet 5",
header = c("ODD HEAD LEFT", "ODD HEAD CENTER", "ODD HEAD RIGHT"),
footer = c("ODD FOOT RIGHT", "ODD FOOT CENTER", "ODD FOOT RIGHT"),
evenHeader = c("EVEN HEAD LEFT", "EVEN HEAD CENTER", "EVEN HEAD RIGHT"),
evenFooter = c("EVEN FOOT RIGHT", "EVEN FOOT CENTER", "EVEN FOOT RIGHT"),
firstHeader = c("TOP", "OF FIRST", "PAGE"),
firstFooter = c("BOTTOM", "OF FIRST", "PAGE"))

addWorksheet(wb, "Sheet 6",
             header = c("&[Date]", "ALL HEAD CENTER 2", "&[Page] / &[Pages]"),
             footer = c("&[Path]&[File]", NA, "&[Tab]"),
             firstHeader = c(NA, "Center Header of First Page", NA),
             firstFooter = c(NA, "Center Footer of First Page", NA))

addWorksheet(wb, "Sheet 7",
             header = c("ALL HEAD LEFT 2", "ALL HEAD CENTER 2", "ALL HEAD RIGHT 2"),
             footer = c("ALL FOOT RIGHT 2", "ALL FOOT CENTER 2", "ALL FOOT RIGHT 2"))

addWorksheet(wb, "Sheet 8",
             firstHeader = c("FIRST ONLY L", NA, "FIRST ONLY R"),
             firstFooter = c("FIRST ONLY L", NA, "FIRST ONLY R"))

## Need data on worksheet to see all headers and footers
writeData(wb, sheet = 5, 1:400)
writeData(wb, sheet = 6, 1:400)
writeData(wb, sheet = 7, 1:400)
writeData(wb, sheet = 8, 1:400)

## Save workbook
saveWorkbook(wb, "addWorksheetExample.xlsx", overwrite = TRUE)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.