[英]Change font style depending on value in flextable
如果 Value > 10,我想將字體更改為粗體和紅色。如何在 flextable 中實現?
我的例子:
file_path <- "c:\\temp\\test_table.docx"
df <- data.frame(
InstanceName = c("Instance1", "Instance2", "Instance3", "Instance4", "Instance5"),
Value = c(15, 5, 11, 0, 5)
)
table_to_save <- flextable(df)
save_as_docx(
table_to_save,
path = file.path(file_path)
)
我想要的是:
library(flextable)
library(magrittr)
df <- data.frame(
InstanceName = c("Instance1", "Instance2", "Instance3", "Instance4", "Instance5"),
Value = c(15, 5, 11, 0, 5)
)
flextable(df) %>%
color(i = ~ Value > 10, j = "Value", color = "red") %>%
bold(i = ~ Value > 10, j = "Value")
請注意,所有這些都記錄在此處: https : //ardata-fr.github.io/flextable-book/format.html#usual-functions-for-formatting
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.