1

My prior understanding was that the ability to utilize Microsoft Word Table styles is only available in the officedown package, but syntax like

read_docx(path = "reports/template.docx") %>%
body_add_flextable(my_ft) %>%
print(target = "reports/example_template.docx")

suggests some ability to format Word flextable objects, e.g. those one would use for outputting regressions, according to Word document Table-styles? Is this feature available in the officer package? If so, how do I use it?

1 Answers1

2

You can use body_add_table():

doc <- read_docx()
doc <- body_add_table(doc, iris, style = "table_template")
print(doc, target = tempfile(fileext = ".docx") )

But flextable objects cannot be associated with a specific Word table template. To style a flextable object, you can only use flextable functions.

David Gohel
  • 9,180
  • 2
  • 16
  • 34
  • Thank you, but can I adapt this to output ```flextable``` objects, e.g. regression tables etc., in Word formats, rather than just ```data.frames```? – Michael Lachanski Jan 04 '22 at 16:44
  • No, this is not the way it works with flextable – David Gohel Jan 04 '22 at 17:09
  • Right so the answer to my question is really "no, ```flextable``` objects cannot be exported into a Word document with a specific Table format", but I have approved your answer because it is closest to what I wanted and may be helpful to others. – Michael Lachanski Jan 04 '22 at 17:19
  • I've updated the answer – David Gohel Jan 04 '22 at 17:44
  • Thanks, I've accepted the question and will upvote it when I have enough credit on this site. I have asked a related question here: https://stackoverflow.com/questions/70583223/how-to-combine-flextable-and-officedown-to-output-flextable-objects-with-a-parti – Michael Lachanski Jan 04 '22 at 18:27
  • to me it's the same question. flextable objects cannot be associated with a specific Word table template. – David Gohel Jan 04 '22 at 20:08
  • Right, so the recommended procedure for ```flextable``` objects is to format them in Word manually after outputting them with ```officer```? – Michael Lachanski Jan 04 '22 at 22:38
  • No, you can format flextable as you want, with r functions, see https://ardata-fr.github.io/flextable-gallery/gallery/ and https://ardata-fr.github.io/flextable-book/ – David Gohel Jan 04 '22 at 22:46
  • Thank you. Many of the ```flextable``` examples are impressive, but I find that I must often make some slight changes to exported Word tables, e.g. to the Table border style for the footer of the table to make it a double-line, changing fonts, etc. In ```officer```, as you pointed out in your answer, I can make those changes by specifying a Word Table-style in advance and using that template with a data.frame. Is it impossible to use pre-specified Word formats for changes like that for ```flextable``` objects? – Michael Lachanski Jan 04 '22 at 23:12
  • the answer is still no – David Gohel Jan 05 '22 at 07:59