【问题标题】:Change font style depending on value in flextable根据 flextable 中的值更改字体样式
【发布时间】:2021-12-17 20:58:12
【问题描述】:

如果 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)
)

我想要什么:

【问题讨论】:

    标签: r flextable


    【解决方案1】:
    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

    【讨论】:

    • 感谢您的图书馆。但我有一个问题要问你。我们可以用flextable 制作一个带有多个面板的表格,例如:newbedev.com/tables-with-multiple-panels-in-latex-r-and-sweave 吗?
    • 你的问题和OP的问题有什么关系?
    • 我记得这个问题已经在 SO,github 上交叉发布,没有任何代表,就像这个问题一样......
    • 没有关系。是的,一个人在这里问。我试图帮助他,但无能为力。现在对我来说也很有趣;)
    • 如果没有数据也没有最小可复现的例子,我帮不上忙!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-15
    • 2017-06-03
    • 1970-01-01
    • 1970-01-01
    • 2011-12-02
    相关资源
    最近更新 更多