## write to working directory
options("openxlsx.borderColour" = "#4F80BD") ## set default border colour
if (FALSE) {
write.xlsx(iris, file = "writeXLSX1.xlsx", colNames = TRUE, borders = "columns")
write.xlsx(iris, file = "writeXLSX2.xlsx", colNames = TRUE, borders = "surrounding")
}
hs <- createStyle(
textDecoration = "BOLD", fontColour = "#FFFFFF", fontSize = 12,
fontName = "Arial Narrow", fgFill = "#4F80BD"
)
if (FALSE) {
write.xlsx(iris,
file = "writeXLSX3.xlsx",
colNames = TRUE, borders = "rows", headerStyle = hs
)
}
## Lists elements are written to individual worksheets, using list names as sheet names if available
l <- list("IRIS" = iris, "MTCATS" = mtcars, matrix(runif(1000), ncol = 5))
if (FALSE) {
write.xlsx(l, "writeList1.xlsx", colWidths = c(NA, "auto", "auto"))
}
## different sheets can be given different parameters
if (FALSE) {
write.xlsx(l, "writeList2.xlsx",
startCol = c(1, 2, 3), startRow = 2,
asTable = c(TRUE, TRUE, FALSE), withFilter = c(TRUE, FALSE, FALSE)
)
}
# specify column widths for multiple sheets
if (FALSE) {
write.xlsx(l, "writeList2.xlsx", colWidths = 20)
write.xlsx(l, "writeList2.xlsx", colWidths = list(100, 200, 300))
write.xlsx(l, "writeList2.xlsx", colWidths = list(rep(10, 5), rep(8, 11), rep(5, 5)))
}
Run the code above in your browser using DataLab