Several lines with different style in Caption in both html and docx - flextable

Viewed 134

I need to show data caption, computer name and period in the header of table.

I have also requirements: zebra theme, merging cells if needed. That's why I chose flextable.

Here is my code:

library(officer) # border settings library
library(flextable) # drawing tables library

library(dplyr)


Caption <- "<b><big>Computer01.domain.com</big></b><br>Network Interface<br>Gbit Total/sec<br><small>2021-05-14 18:04 to 2021-05-25 13:29</small>"

bold_border <- fp_border(color="gray", width =2)
std_border <-  fp_border(color="gray") 

stub <- "2021-05-14 01:40 to 2021-05-17 08:26"

table_data <- data.frame (
  
  Instance = c("Intel[R] Ethernet 10G",
               "Intel[R] Ethernet Converged Network Adapter _1",
               "Intel[R] Ethernet Converged Network Adapter _2",
               "Intel[R] Ethernet 10G",
               "Intel[R] Gigabit"),
  Max = c(2.45, 2.41, 2.29, 2.17, 0),
  Avg = c(0.15, 0.15, 0.15, 0.17, 0)
)

table <- table_data %>% flextable() %>% 
  set_caption(caption = Caption , html_escape = F) %>% 
  bg(bg = "#579FAD", part = "header") %>% 
  color(color = "white", part = "header") %>% 
  theme_zebra(
    odd_header = "#579FAD",
    odd_body = "#E0EFF4",
    even_header = "transparent",
    even_body = "transparent"
  ) %>% 
  set_table_properties(width = 1, layout = "autofit") %>% 
  hline(part="all", border = std_border ) %>% 
  vline(part="all", border = std_border ) %>% 
  border_outer( border = bold_border, part = "all" ) %>%
  fix_border_issues() %>% 
  set_header_labels(
    values = list(Instance = InstanceName ) ) %>% 
  flextable::font (part = "all" , fontname = "Calibri")

save_as_docx( table, path =  file.path("c:\\temp", "test01.docx") )
save_as_html (table, path = file.path("c:\\temp", "test01.html"))

Here is what I got in html which is okay for me: enter image description here

But in docx format my header style is not applied:

enter image description here

How can I create header like I did for html that can be saved to both html and docx?

If I have to create separate tables - one for html, other for docx - it's not so good but acceptable options. That case my question how to create header I made in html but for docx format?

0 Answers
Related