writeData(wb, sheet, x, startCol = 1, startRow = 1, xy = NULL,
colNames = TRUE, rowNames = FALSE, headerStyle = NULL,
borders = c("none", "surrounding", "rows", "columns", "all"),
borderColour = getOption("openxlsx.borderColour", "black"),
borderStyle = getOption("openxlsx.borderStyle", "thin"),
withFilter = FALSE, keepNA = FALSE)
startCol
and
startRow
individually. A vector of the form
c(startCol, startRow)
.TRUE
, column names of x are written.TRUE
, data.frame row names of x are written.none
" (default), "surrounding
",
"columns
", "rows
" or respective abbreviations. If
"surrounding
", a border is drawn around the data. If "rows
",
a surroundincolours()
or a hex colour code, eg see writeDataTable
## See formatting vignette for further examples.
wb <- createWorkbook()
options("openxlsx.borderStyle" = "thin")
options("openxlsx.borderColour" = "#4F81BD")
## Add worksheets
addWorksheet(wb, "Cars")
x <- mtcars[1:6,]
writeData(wb, "Cars", x, startCol = 2, startRow = 3, rowNames = TRUE)
writeData(wb, "Cars", x, rowNames = TRUE, startCol = "O", startRow = 3,
borders="surrounding", borderColour = "black") ## black border
writeData(wb, "Cars", x, rowNames = TRUE,
startCol = 2, startRow = 12, borders="columns")
writeData(wb, "Cars", x, rowNames = TRUE,
startCol="O", startRow = 12, borders="rows")
## header styles
hs1 <- createStyle(fgFill = "#DCE6F1", halign = "CENTER", textDecoration = "Italic",
border = "Bottom")
writeData(wb, "Cars", x, colNames = TRUE, rowNames = TRUE, startCol="B",
startRow = 23, borders="rows", headerStyle = hs1, borderStyle = "dashed")
hs2 <- createStyle(fontColour = "#ffffff", fgFill = "#4F80BD",
halign = "center", valign = "center", textDecoration = "Bold",
border = "TopBottomLeftRight")
writeData(wb, "Cars", x, colNames = TRUE, rowNames = TRUE,
startCol="O", startRow = 23, borders="columns", headerStyle = hs2)
## Write a hyperlink vector
v <- rep("http://cran.r-project.org/", 4)
names(v) <- paste("Hyperlink", 1:4) # Names will be used as display text
class(v) <- 'hyperlink'
writeData(wb, "Cars", x = v, xy = c("B", 32))
## Save workbook
saveWorkbook(wb, "writeDataExample.xlsx", overwrite = TRUE)
Run the code above in your browser using DataLab