library(officer)
library(flextable)
# cell to highlight
vary_i <- 1:3
vary_j <- 1:3
std_border <- fp_border(color = "orange")
ft <- flextable(head(iris))
ft <- border_remove(x = ft)
ft <- border_outer(x = ft, border = std_border)
for (id in seq_along(vary_i)) {
ft <- bg(
x = ft,
i = vary_i[id],
j = vary_j[id], bg = "yellow"
)
ft <- surround(
x = ft,
i = vary_i[id],
j = vary_j[id],
border.left = std_border,
border.right = std_border,
part = "body"
)
}
ft <- autofit(ft)
ft
# # render
# print(ft, preview = "pptx")
# print(ft, preview = "docx")
# print(ft, preview = "pdf")
# print(ft, preview = "html")
Run the code above in your browser using DataLab