davidgohel / ReporteRs

Note that ReporteRs has been removed from CRAN the 16th of July 2018 and is not maintained anymore. please migrate to officer.
244 stars 44 forks source link

addBookmark function #148

Closed slarge closed 8 years ago

slarge commented 8 years ago

I need to generate multiple reports from a single docx template - incredibly easy thanks to this package (thanks!). At a later stage, I would like to be able to add figures, text, or tables at bookmarks generated while modifying the original docx template. I think, in principle, this is a similar request as Issue 145. Perhaps the simple way to do this is to have a function like addBookmark(). Simple example follows. I commented out my pseudo-code for how such a function might appear. Thanks in advance for your help!

library( ReporteRs )
library( ggplot2 )

# Template from http://davidgohel.github.io/ReporteRs/files/word/word_bookmark_template.docx
mydoc <- docx( template = "files/word/word_bookmark_template.docx" )

authorList <- c("Randy", "Ted", "Marvin", "Norton") 

# replace bookmarks 'AUTHOR'
for(i in authorList)

mydoc <- addParagraph( mydoc
                       , value = i   
                       , stylename = "small"
                       , bookmark = "AUTHOR" )
# add bookmark value "BookmarkMe", here:
#mydoc <- addBookmark( mydoc
#                      , value = "BookmarkMe" )

writeDoc( mydoc, file = paste0("files/word/word_replacement-", i, ".docx"))
}

# Later, for each report, I can replace bookmarks 'BookmarkMe'
mydoc <- docx( "files/word/word_bookmark-Norton.docx" )
mydoc <- addPlot( mydoc, fun = print, x = myplot1, bookmark = "BookmarkMe" )
writeDoc( mydoc, file = "files/word/word_replacement-Norton.docx")
davidgohel commented 8 years ago

Hi,

Thanks for the suggestion. I will work on the bookmark system soon.

David

davidgohel commented 8 years ago

I think #145 is a solution for your question. You don't really need to add bookmarks if they are kept after replacement.