关于R中的openxlsx包的问题:
我尝试用函数headerStyle ()来更改“openxlsx_setOp”的默认选项,但我做不到。
为了不每次都在writeData()中定义writeData。
例如:
openxlsx_getOp("headerStyle")
NULL
style <- createStyle(borderColour = "grey")
openxlsx_setOp("headerStyle", style)
openxlsx_getOp("headerStyle")
NULL提前谢谢。
发布于 2022-08-18 17:06:33
这可能是一个bug (我打开了一个问题)。问题是,openxlsx_setOp在引擎盖下使用as.list将value参数转换为list。作为一种解决办法,您可以通过headerStyle通过options设置如下所示:
library(openxlsx)
openxlsx_getOp("headerStyle")
#> NULL
style <- createStyle(borderColour = "grey")
options(openxlsx.headerStyle = createStyle(borderColour = "grey"))
openxlsx_getOp("headerStyle")
#> A custom cell style.
#>
#> Cell formatting: GENERAL
#> 简单地将as.list替换为list似乎解决了这个问题(至少在这种情况下是这样):
library(openxlsx)
openxlsx_getOp("headerStyle")
#> NULL
style <- createStyle(borderColour = "grey")
openxlsx_setOp2 <- function (x, value) {
if (is.list(x)) {
if (is.null(names(x))) {
stop("x cannot be an unnamed list", call. = FALSE)
}
return(invisible(mapply(openxlsx_setOp, x = names(x),
value = x)))
}
value <- list(value)
names(value) <- openxlsx:::check_openxlsx_op(x)
options(value)
}
openxlsx_setOp2("headerStyle", createStyle(borderColour = "grey"))
openxlsx_getOp("headerStyle")
#> A custom cell style.
#>
#> Cell formatting: GENERAL
#> https://stackoverflow.com/questions/73406826
复制相似问题