I have a need to replace nearly a hundred tables in a word document with updated data (not always the same number of rows and cols).
Each table has a "Table heading" I can find in the docx_summary results...
I have found this (not working) link in a previous Q&A which I assume answers my question... https://davidgohel.github.io/officer/articles/officer_reader.html#word-tables
Can we replace all of the cells in the docx_summary data frame with new data and somehow update the document object and then update the doc object and print to file?
If not how would I select the entire table and replace with a new one?
#--- load the (Huge) document
dcx <- officer::read_docx(path = prm.A05.destdoc)
dcx.summ <- officer::docx_summary(x = dcx)
dcx.tableheads <- dcx.summ %>% dplyr::filter(style_name == "Table heading")
dcx.tablecells <- dcx.summ %>% dplyr::filter(content_type == "table cell")
#--- find a specific table
i.table <- 3
i.dxc.tablehead <- dcx.tableheads %>% dplyr::filter( stringr::str_detect(string = dcx.tableheads$text, pattern = " SEQ Table")
& (
stringr::str_detect(string = text, pattern = paste0( "ARABIC ", i.table, ":"))
| stringr::str_detect(string = text, pattern = paste0( "ARABIC", i.table, ":"))
)
)
#--- get the cell data
i.dxc.tablecells <- dcx.tablecells %>% dplyr::filter( doc_index == (i.dxc.tablehead[1]$doc_index+1) )
#now what???