I'm creating a Word report using officer and flextable. Among others, I'm creating a flextable.
The problem is that after printing it into Word, while trying to open, the document is showing error: "there is an error with its contents" ("the file is corrupt"). Then I click OK and Word asks if to recover the contents. I click YES and the new document is being open with my data.
After removing flextable, Word is opening without error.
ft <- data.frame(c("data1", "data2"), c("text", variable1)) %>%
flextable() %>% theme_box() %>%
delete_part(part = "header")
add_tab <- function(doc, placeholder, flextable, is_roman = FALSE) {
doc %>% remove_placeholder(placeholder) %>%
body_add_flextable(value = flextable, pos = "after") %>%
body_add_par("")}
final_doc <- read_docx("C:/Users/Template.docx") %>%
add_tab(placeholder = "[table0]", flextable = ft) %>%
print("Output.docx")
How to avoid error masagges while opening the Word document with flextables?