Auto populate Ms Word Table

24 views
Skip to first unread message

ignacio martinez

unread,
May 9, 2017, 1:48:23 PM5/9/17
to ReporteRs
Hi,

I would like to use R to fill up an empty word table shell. For example:

I'm able to create a word table, but i'm it does not look like what i want:

    library("ReporteRs")
    
    fake_data <- data.frame("Variable 1" = rnorm(5), "Variable 2" = rnorm(5),
                            "Variable 3" = rnorm(5), "Variable 4" = rnorm(5))
    # Create a word document
    doc <- docx(template="empty_table.docx")
    
    # Add table
    doc <- addFlexTable(doc, vanilla.table(fake_data))
    # Write the word document to a file
    writeDoc(doc, file="example.docx")


Is it possible to do what I want? If so, what am I missing?

Thanks!

Ignacio
empty_table.docx

John Vida

unread,
Jun 2, 2017, 2:50:27 PM6/2/17
to ReporteRs
You need to customize your data (i.e the table) to look like the way you want. To fill up an empty word shell table, you need to assign bookmarks in each shell and feed the data to each bookmarks (which is cumbersome).

For your need, grab the data, and feed it to FlexTable object and apply vanilla style and then print on an empty doc. it will be easier to customize colors of certain column.
Reply all
Reply to author
Forward
0 new messages