Table-wide 合并单元格下的水平边框在 docx 中不显示(但在其他格式上显示正常)

Table-wide horizontal border under merged cells do not show up in docx (but display fine on other format)

上下文: 使用描述的技巧 我能够在合并的单元格下得到水平线。

问题: 当我使用 save_as_docx() 时,第一列(包含合并单元格的列)的底线不显示。此外,最后一行底线的格式不正确。 但是,如果我使用任何 .pptx、.html 或 .png 输出,它都可以正常工作。

问题:即使在合并单元格下,是否可以使 .docx 输出具有正确格式的全宽底线?

代表:

library(flextable)
library(officer)
library(dplyr)

bigborder <- fp_border(style = "solid", width=2)

fl <- iris %>% 
  # make iris a smaller dataset for display purpose
  group_by(Species) %>% 
  slice_head(n = 5) %>% 
  # just to have species as the 1st column
  select(Species, everything()) %>% 
  flextable() %>% 
  merge_v(j = ~ Species) %>% 
  # bottom border of column 2:ncol(iris)
  border(border.bottom = bigborder, i = rle(cumsum(.$body$spans$columns[,1] ))$values, j = 2:ncol(iris), part="body") %>% 
  # bottom border of 1st colum
  border(border.bottom = bigborder, i = .$body$spans$columns[,1] > 1, j = 1, part="body")

fl

# Bottom lines of 1st column do not display with docx output
save_as_docx(fl, path = "./fl.docx")

# Bottom lines of 1st column display right with these format
save_as_html(fl, path = "./fl.html")
save_as_pptx(fl, path = "./fl.pptx")
save_as_image(fl, path = "./fl.png")

reprex package (v2.0.0)

创建于 2021-06-02

.docx 输出:

.pptx, .html, .png 输出(预期一个):

刚刚按照建议使用 hline()fix_border_issues() 得到了预期的输出 here

fl <- iris %>% 
  # make iris a smaller dataset for display purpose
  group_by(Species) %>% 
  slice_head(n = 5) %>% 
  # just to have species as the 1st column
  select(Species, everything()) %>% 
  # Flextable
  flextable() %>% 
  merge_v(j = ~ Species) %>% 
  hline(i = rle(cumsum(.$body$spans$columns[,1] ))$values, border = bigborder) %>% 
  fix_border_issues()
fl

.docx 输出: