1

I have a new computer (read: new versions of everything, including Office 2016) I created the following code on my previous computer, and all worked fine:

...
control_table <- regulartable(data = data) %>%
  theme_box() %>%
  rotate(rotation = "btlr", part = "header") %>%
  align(align = "left", part = "body") %>% 
  set_header_labels(Var1 = " " ) %>% 
  align(align = "left", part = "header") %>%
  height(height = 3, part = "header") %>%
  width(width = 0.3) %>%
  width(j = 1, width = 3.5) 

doc <- doc %>%
  cursor_reach("The following table indicates the reports") %>%
  body_add_flextable(control_table, align = "left")
...

now with my new computer the row height of the header is not being translated into the Word document. dim(control_table) gives the correct row height, but the header row height is not displaying in the word document. What am I missing?

HannesP
  • 13
  • 2
  • I have this problem with officer and had to use an archived version of both flextable and officer. I use flextable 0.5.5 and officer 0.3.5 to avoiid this problem – morgan121 Aug 13 '20 at 00:22

1 Answers1

3

Word don't handle auto height with rotated headers, then it is necessary to specify rule for row height with function hrule.

library(flextable)
library(officer)
library(magrittr)

control_table <- flextable(data = head(iris)) %>%
  theme_box() %>%
  rotate(rotation = "btlr", part = "header") %>%
  align(align = "left", part = "body") %>% 
  set_header_labels(Var1 = " " ) %>% 
  align(align = "left", part = "header") %>%
  height(height = 2, part = "header") %>%
  hrule(i = 1, rule = "exact", part = "header")


doc <- read_docx() %>%
  body_add_flextable(control_table, align = "left") %>% 
  print(target = "example.docx")

enter image description here

David Gohel
  • 9,180
  • 2
  • 16
  • 34