Bruno Guarita
Bruno Guarita

Reputation: 817

Change margins with officer

I am trying change the properties of a word document with the officer library and I am having problems to succeed.

I need to change the margins of the entire document.

Let's say I have this document:

barometer <- read_docx %>%
  body_add_par("A title", style = "heading 1") %>%   
  body_add_par("Hello world!", style = "Normal") %>%
  print(target = "test.docx")

Does any one knowns to set the margins of the document?

Thanks!

Upvotes: 2

Views: 856

Answers (1)

Carl Witthoft
Carl Witthoft

Reputation: 21532

Do it the correct and easy way. First, open any word document and change everything to be exactly as you want it: font, indents, margins, etc. Then save that layout as a new Style. Then over in officeR all you need to do is specify that style rather than "Normal."

If something like page margins aren't included in the Style (I forget at the moment), then go one step farther, again in Word. Do everything I listed in the first paragraph. Make sure there's no text or pictures or whatever in the document (completely blank). Then SaveAs and select ".dot" or ".dotx" to save as a document template. Now when you run officeR you can specify that template and a new ".docx" file will be created. You can name it and save it with officeR commands.

Upvotes: 2

Related Questions