Add a flextable at a bookmark in the body of a word document from R
up vote
1
down vote
favorite
I'm trying to add a flextable at a specific bookmark within the body of a Word document. So far I have found the following options:
- footers_flextable_at_bkm {flextable}
- headers_flextable_at_bkm {flextable}
- body_add_flextable {flextable}
But none of them do exactly what I need.
I tried to write my own code to do it (see below), but it says that the docx_str
function is not found. (I coped/modified this code from the headers_flextable_at_bkm
function). Does anyone have a way to do this? Or is it a fuction that could be added to the flextable package?
body_flextable_at_bkm <- function(x, bookmark, value){
stopifnot(inherits(x, "rdocx"), inherits(value, "flextable"))
str <- docx_str(value, doc = x, align = "center")
xml_elt <- as_xml_document(x)
for(doc_obj in x$body){
if( doc_obj$has_bookmark(bookmark) ){
doc_obj$cursor_bookmark(bookmark)
cursor_elt <- doc_obj$get_at_cursor()
xml_replace(cursor_elt, xml_elt)
}
}
}
r flextable officer
add a comment |
up vote
1
down vote
favorite
I'm trying to add a flextable at a specific bookmark within the body of a Word document. So far I have found the following options:
- footers_flextable_at_bkm {flextable}
- headers_flextable_at_bkm {flextable}
- body_add_flextable {flextable}
But none of them do exactly what I need.
I tried to write my own code to do it (see below), but it says that the docx_str
function is not found. (I coped/modified this code from the headers_flextable_at_bkm
function). Does anyone have a way to do this? Or is it a fuction that could be added to the flextable package?
body_flextable_at_bkm <- function(x, bookmark, value){
stopifnot(inherits(x, "rdocx"), inherits(value, "flextable"))
str <- docx_str(value, doc = x, align = "center")
xml_elt <- as_xml_document(x)
for(doc_obj in x$body){
if( doc_obj$has_bookmark(bookmark) ){
doc_obj$cursor_bookmark(bookmark)
cursor_elt <- doc_obj$get_at_cursor()
xml_replace(cursor_elt, xml_elt)
}
}
}
r flextable officer
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm trying to add a flextable at a specific bookmark within the body of a Word document. So far I have found the following options:
- footers_flextable_at_bkm {flextable}
- headers_flextable_at_bkm {flextable}
- body_add_flextable {flextable}
But none of them do exactly what I need.
I tried to write my own code to do it (see below), but it says that the docx_str
function is not found. (I coped/modified this code from the headers_flextable_at_bkm
function). Does anyone have a way to do this? Or is it a fuction that could be added to the flextable package?
body_flextable_at_bkm <- function(x, bookmark, value){
stopifnot(inherits(x, "rdocx"), inherits(value, "flextable"))
str <- docx_str(value, doc = x, align = "center")
xml_elt <- as_xml_document(x)
for(doc_obj in x$body){
if( doc_obj$has_bookmark(bookmark) ){
doc_obj$cursor_bookmark(bookmark)
cursor_elt <- doc_obj$get_at_cursor()
xml_replace(cursor_elt, xml_elt)
}
}
}
r flextable officer
I'm trying to add a flextable at a specific bookmark within the body of a Word document. So far I have found the following options:
- footers_flextable_at_bkm {flextable}
- headers_flextable_at_bkm {flextable}
- body_add_flextable {flextable}
But none of them do exactly what I need.
I tried to write my own code to do it (see below), but it says that the docx_str
function is not found. (I coped/modified this code from the headers_flextable_at_bkm
function). Does anyone have a way to do this? Or is it a fuction that could be added to the flextable package?
body_flextable_at_bkm <- function(x, bookmark, value){
stopifnot(inherits(x, "rdocx"), inherits(value, "flextable"))
str <- docx_str(value, doc = x, align = "center")
xml_elt <- as_xml_document(x)
for(doc_obj in x$body){
if( doc_obj$has_bookmark(bookmark) ){
doc_obj$cursor_bookmark(bookmark)
cursor_elt <- doc_obj$get_at_cursor()
xml_replace(cursor_elt, xml_elt)
}
}
}
r flextable officer
r flextable officer
edited Oct 1 at 1:34
kenlukas
1,2321217
1,2321217
asked Oct 1 at 1:30
Anna Burn
949
949
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
This function should do what you need:
body_flextable_at_bkm <- function(x, bookmark, value){
x <- cursor_bookmark(x, bookmark)
x <- body_add_flextable(x = x, value = value, pos = "on")
x
}
On another note, is there way to automatically calculate and add column sums into the footer of a table?
– Anna Burn
Oct 3 at 4:02
add a comment |
up vote
0
down vote
After a bit more digging there is a workaround where you add set_curser(x, bookmarkID)
before the body_add_flextable(x, flextable)
command.
For consistaency it would still be nice to have the body_flextable_at_bkm
as part of the flextable package so it can be used like headers_flextable_at_bkm
and footers_flextable_at_bkm
commands.
Edit: the body_flextable_at_bkm
command should now work with the latest version of the package.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
This function should do what you need:
body_flextable_at_bkm <- function(x, bookmark, value){
x <- cursor_bookmark(x, bookmark)
x <- body_add_flextable(x = x, value = value, pos = "on")
x
}
On another note, is there way to automatically calculate and add column sums into the footer of a table?
– Anna Burn
Oct 3 at 4:02
add a comment |
up vote
1
down vote
accepted
This function should do what you need:
body_flextable_at_bkm <- function(x, bookmark, value){
x <- cursor_bookmark(x, bookmark)
x <- body_add_flextable(x = x, value = value, pos = "on")
x
}
On another note, is there way to automatically calculate and add column sums into the footer of a table?
– Anna Burn
Oct 3 at 4:02
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
This function should do what you need:
body_flextable_at_bkm <- function(x, bookmark, value){
x <- cursor_bookmark(x, bookmark)
x <- body_add_flextable(x = x, value = value, pos = "on")
x
}
This function should do what you need:
body_flextable_at_bkm <- function(x, bookmark, value){
x <- cursor_bookmark(x, bookmark)
x <- body_add_flextable(x = x, value = value, pos = "on")
x
}
answered Oct 1 at 7:53
David Gohel
2,4322614
2,4322614
On another note, is there way to automatically calculate and add column sums into the footer of a table?
– Anna Burn
Oct 3 at 4:02
add a comment |
On another note, is there way to automatically calculate and add column sums into the footer of a table?
– Anna Burn
Oct 3 at 4:02
On another note, is there way to automatically calculate and add column sums into the footer of a table?
– Anna Burn
Oct 3 at 4:02
On another note, is there way to automatically calculate and add column sums into the footer of a table?
– Anna Burn
Oct 3 at 4:02
add a comment |
up vote
0
down vote
After a bit more digging there is a workaround where you add set_curser(x, bookmarkID)
before the body_add_flextable(x, flextable)
command.
For consistaency it would still be nice to have the body_flextable_at_bkm
as part of the flextable package so it can be used like headers_flextable_at_bkm
and footers_flextable_at_bkm
commands.
Edit: the body_flextable_at_bkm
command should now work with the latest version of the package.
add a comment |
up vote
0
down vote
After a bit more digging there is a workaround where you add set_curser(x, bookmarkID)
before the body_add_flextable(x, flextable)
command.
For consistaency it would still be nice to have the body_flextable_at_bkm
as part of the flextable package so it can be used like headers_flextable_at_bkm
and footers_flextable_at_bkm
commands.
Edit: the body_flextable_at_bkm
command should now work with the latest version of the package.
add a comment |
up vote
0
down vote
up vote
0
down vote
After a bit more digging there is a workaround where you add set_curser(x, bookmarkID)
before the body_add_flextable(x, flextable)
command.
For consistaency it would still be nice to have the body_flextable_at_bkm
as part of the flextable package so it can be used like headers_flextable_at_bkm
and footers_flextable_at_bkm
commands.
Edit: the body_flextable_at_bkm
command should now work with the latest version of the package.
After a bit more digging there is a workaround where you add set_curser(x, bookmarkID)
before the body_add_flextable(x, flextable)
command.
For consistaency it would still be nice to have the body_flextable_at_bkm
as part of the flextable package so it can be used like headers_flextable_at_bkm
and footers_flextable_at_bkm
commands.
Edit: the body_flextable_at_bkm
command should now work with the latest version of the package.
edited Nov 8 at 4:09
answered Oct 1 at 2:42
Anna Burn
949
949
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52583571%2fadd-a-flextable-at-a-bookmark-in-the-body-of-a-word-document-from-r%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown