wb <- wb_workbook()
wb$add_worksheet("Sheet 1")
wb$add_worksheet("Sheet 2")
wb$add_data_table(1, x = iris[1:30, ])
wb$add_data_validation(1,
dims = "A2:C31", type = "whole",
operator = "between", value = c(1, 9)
)
wb$add_data_validation(1,
dims = "E2:E31", type = "textLength",
operator = "between", value = c(4, 6)
)
## Date and Time cell validation
df <- data.frame(
"d" = as.Date("2016-01-01") + -5:5,
"t" = as.POSIXct("2016-01-01") + -5:5 * 10000
)
wb$add_data_table(2, x = df)
wb$add_data_validation(2, dims = "A2:A12", type = "date",
operator = "greaterThanOrEqual", value = as.Date("2016-01-01")
)
wb$add_data_validation(2,
dims = "B2:B12", type = "time",
operator = "between", value = df$t[c(4, 8)]
)
######################################################################
## If type == 'list'
# operator argument is ignored.
wb <- wb_workbook()
wb$add_worksheet("Sheet 1")
wb$add_worksheet("Sheet 2")
wb$add_data_table(sheet = 1, x = iris[1:30, ])
wb$add_data(sheet = 2, x = sample(iris$Sepal.Length, 10))
wb$add_data_validation(1, dims = "A2:A31", type = "list", value = "'Sheet 2'!$A$1:$A$10")
Run the code above in your browser using DataLab