Convert ODK‐style XLSForm questionnaires into neatly formatted Microsoft Word (.docx
) documents.
From CRAN:
install.packages("convertxlsform")
Or the latest development version on GitHub:
# install.packages("devtools")
# (explicitly specify the 'main' branch)
devtools::install_github("masud90/convertxlsform@main")
library(convertxlsform)
convertxlsform("survey.xlsx")
#> Document generated in 0.42 secs: /full/path/survey.docx
convertxlsform(
xlsform_path = "survey.xlsx",
selected_language = "en",
output_docx = "reports/MyForm.docx"
)
convertxlsform("survey.xlsx", number_questions = FALSE)
convertxlsform(
xlsform_path, # (chr) Path to XLSForm .xlsx
selected_language = "en", # (chr) language code (must match label::<lang> column)
output_docx = NULL, # (chr) destination .docx (defaults to basename(xlsx))
number_questions = TRUE # (bool) nested numbering of questions/groups
)
survey
sheet withtype
,name
,label
columns (and optionallabel::<lang>
,hint::<lang>
,instructions::<lang>
,required
,relevant
,constraint_message
,parameters
,repeat_count
).choices
sheet withlist_name
,name
,label
column (and optionallabel::<lang>
,image
).settings
sheet withform_title
column (and optionalform_title::<lang>
).- If you have image files in the CAPI and wish for them to appear in the PAPI, upload the files of the same name to the root folder of your project (where the CAPI form is).
- Title: Arial 16 pt, bold, centered.
- Mandatory note: “Mandatory questions are marked with an asterisk (*) symbol.”
- Body text: Arial 11 pt, left-aligned.
- Question numbering: Nested (“1.”, “1.1.” in groups, etc.), default TRUE.
- Notes: Unnumbered, prefixed Note:.
- Select questions:
- select_one, rank, range: hollow‐circle bullets (◯).
- select_multiple: hollow‐square bullets (▢).
- Text/range boxes: bordered tables spanning full width with only blank lines.
- Images:
- Question images: up to 2″ tall.
- Choice images: up to 1″ tall, with warnings if missing.
# Multi‐language support:
convertxlsform("survey_multilang.xlsx", selected_language = "fr")
# Custom output location and no numbering:
convertxlsform(
xlsform_path = "survey.xlsx",
output_docx = "out/MySurvey.docx",
number_questions = FALSE
)
readxl
(read .xlsx)officer
(generate Word docs)commonmark
(Markdown parsing – unused by default)flextable
(create boxed answer fields)magick
(image sizing)stats
(utility setNames)
This project is licensed under the MIT license. See LICENSE for full text.
Clone the repo and send a pull request.