How can I generate content in MSWord that uses MSWord paragraph styles, respects tab stops and preserves the use of tab within a string? Here is what it should look like if tabs / tab stops are used. The body_add function escapes special characters. In the sectond item, the tab was treated as two spaces. We can see in the image first and third tabs were treated as escaped strings. Here is the content saved to test.docx.Īs shown, the tab stop still exists in the paragraph style but the "value" part of the label/value set is not tabbed over. The script works as expected except for the tabs. Note that in the first detail item, I added the Word xml tag for a tab, in the second detail item, I used a tab character (using the tab key) within the value string, and in the third I used html character for a horizontal tab. # Open an MSWord document containing the style definitionsĭoc % body_add_par("Item #001: The first item", style = "Equip Header")ĭoc % body_add_par("QUANTITY:One (1)", style = "Equip Detail")ĭoc % body_add_par("PROVIDED BY: K.E.C.", style = "Equip Detail")ĭoc % body_add_par("PROVIDED BY: K.E.C.", style = "Equip Detail") In R, I generate the content as follows: library(officer) (Note: I cannot post a Word file - see end of post for steps to create a minimally reproducible MSWord template document however, the challenge appears to be how tabs are handled by officer.) The template file is empty, but contains the style definitions we need. The tab stop is defined by the paragraph style in an existing MSWord document that is referenced as a template. I am generating a formatted collection of itemized details (similar to a catalog) in MSWord using the officer package.Įach item in the collection has a header followed by a line for each defined detail.Įach line (header or detail) has a label, followed by a tab, then the value.įor example: Item #001 The Name of the First Item
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |