# NOT RUN {
library(flextable)
ft <- flextable(head(iris))
# measure column widths but only for the body part
w_body <- dim_pretty(ft, part = "body")$widths
# measure column widths only for the header part and get the max
# as height value for rotated text
h_header <- max( dim_pretty(ft, part = "header")$widths )
ft <- rotate(ft, j = 1:4, rotation="btlr",part="header")
ft <- rotate(ft, j = 5, rotation="tbrl",part="header")
ft <- valign(ft, valign = "center", part = "header")
ft <- align(ft, align = "center", part = "all")
# Manage header height
ft <- height(ft, height = h_header * 1.1, part = "header")
# ... mainly because Word don't handle auto height with rotated headers
ft <- hrule(ft, i = 1, rule = "exact", part = "header")
ft
# }
Run the code above in your browser using DataLab