简体   繁体   中英

Row heigth with flextable and officer

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?

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")

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM