Reputation: 2977
Context: using the tricks described here I was able to get horizontal line under merged cells.
Problem: when I use save_as_docx()
, the bottom lines of the 1st column (the one with merged cells) do not show up. In addition, format of the bottom line of the last row it not correct.
However, if I use any of .pptx, .html or .png outputs, it works fine.
Question: is it possible to make .docx output have full width bottom lines with correct format even under merged cells?
Reprex:
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")
Created on 2021-06-02 by the reprex package (v2.0.0)
.docx output:
.pptx, .html, .png output (expected one):
Upvotes: 0
Views: 538
Reputation: 2977
Just got the expected output using hline()
and fix_border_issues()
as recommended 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 output:
Upvotes: 1