Problem solving the 'file is corrupted' in Word problem #591
Mike-Monash
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have just spent half over a day trying to solve an issue in Officer I found - and I am happy to report a solution. I had been using R to create a customised docx file, with ggplot images and Flextable tables, by knitting an rmd file. I wished to combine this with a standard introduction and appendix section (both docx files, created directly in Word) using the body_add_docx function.
But I couldn't - or to be precise, every time I opened up the combined document, I would get the dreaded 'The file is corrupt and cannot be opened' error message in Word (similar to what has been reported in the issues section, ie. #464 ) . If I opened up this file anyway, the resulting Word document did not have the second document included.
I could reproduce all of the supplied examples in the help files just fine, and I was using the latest version of Officer and Officedown.
I really wanted to produce these combined documents, as it would make a huge difference to some projects I am working on. So I pressed on, just kept on trying different things - and can report a solution.
I found that if I imported and then saved a new version of each of the documents using Officer, i.e
read_docx(path = here("Instructions/Report Introduction.docx")) %>%
print(target = here("Instructions/approved_intro.docx"))
I could then combine these 'approved' documents and it would all play nicely:
read_docx(path = here("Instructions/approved_intro.docx")) %>%
body_add_break() %>%
body_add_docx(src=here("Instructions/approved_site_1_plot.docx")) %>%
body_add_break() %>%
body_add_docx(src=here("Instructions/approved_app.docx")) %>%
print(target = here("Outputs/Site word outputs/site_1_combined.docx"))
The new site_1_combined.docx file opens as it should.
Anyway - someone else may benefit from this finding. Otherwise - nice package !
Beta Was this translation helpful? Give feedback.
All reactions