Replies: 1 comment 1 reply
-
yes, officer produces documents compatible with MS Word or PowerPoint. LibreOffice is a (poor) clone that mimic Word and PowerPoint but don't have all its features. Here, external documents (from call to |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello!
Word generated by the following code cannot be displayed when it is opened using software other than Microsoft Office (for example, WPS Office and LibreOffice). However, it can be opened when it is modified and saved using Microsoft Office.
library(tidyverse)
library(officer)
library(flextable)
library(uuid)
ft <- flextable(iris)
ft <- set_table_properties(ft, layout = "autofit")
gg_plot <- ggplot(data = iris ) +
geom_point(mapping = aes(Sepal.Length, Petal.Length))
tmpdir <- tempfile()
dir.create(tmpdir, showWarnings = FALSE, recursive = TRUE)
tempfiles <- file.path(tmpdir, paste0(UUIDgenerate(n = 10), ".docx") )
for(i in seq_along(tempfiles)) {
doc <- read_docx()
doc <- body_add_par(doc, value = "", style = "Normal")
doc <- body_add_gg(doc, value = gg_plot, style = "centered")
doc <- body_add_par(doc, value = "", style = "Normal")
doc <- body_add_flextable(doc, value = ft)
temp_file <- tempfile(fileext = ".docx")
print(doc, target = tempfiles[i])
}
main_doc <- read_docx()
for(tempfile in tempfiles){
main_doc <- body_add_docx(main_doc, src = tempfile)
}
print(main_doc, target = "example_huge.docx")
Beta Was this translation helpful? Give feedback.
All reactions