我正在将报告转储到文件中,并且我正在使用 openxlsx 来执行此操作,如下所示:
library(openxlsx)
set.seed(100)
dataset <- data.frame(A=runif(100),B=runif(100),C=sample(c("A","B","C"), 100, replace=T))
hs <- createStyle(fontColour = "#ffffff", fgFill = "#4F80BD",
halign = "center", valign = "center", textDecoration = "bold",
border = "TopBottomLeftRight")
wb = createWorkbook()
addWorksheet(wb = wb, sheetName = "example", gridLines = T, zoom = 70)
writeData(
wb,
sheet = "example",
x = dataset,
withFilter=T,
borders="all",
borderStyle="thin",
headerStyle=hs
)
# The width of the columns will be automatically adjusted
setColWidths(wb, sheet = "example", cols=1:ncol(dataset), widths = "auto")
saveWorkbook(wb, "example.xlsx", overwrite=T)
我已经激活了withFilter选项,这样最终用户将能够只选择数据的子集。但是,我想激活一个过滤器,以便默认情况下只显示一个子集;例如,我只想显示 C 列等于“B”的记录。
我已经查看了openxlsx包的文档,但我无法在任何地方找到如何操作。