How can i change specific elements in my Word-Template? (1. Picture, 2. Timespan, 3. ID of Patient)

28 Views Asked by At

I am in desperate need for help for a work project.

I am a psychology student working for my university.

At the moment my task is to create automated participation reminders.

What is the goal?

The goal is to have a Word Document that is always the same apart from these information:

Picture of the clinic logo.

Time window to participate in the survey

Participant ID

So what I am trying to do is, use the template which is finalized, there I have a "free spot" in the upper left corner where the clinic logo should appear.

Also there are two parts in the text which say:

"You time window to participte: **15.02.2024 - 29.02.2024**"
"Your personal ID is: **123456**"

So i have a lot of data. There I search for the people who need to receive the reminder.

After that I want for all of these cases a finished Word Document with the name:

name_of_clinic_id_of_participant.docx

where all the bold typed information a automatically inserted for the case of the participant.

There a lot of participants from different clinics, and I want to automate this process.

Since I am far from being a professional. I read a lot in the office, officedown help site.

I tried different approaches with ChatGPT, but non of them worked. Mostly it says "that function does not exist".

What I archived until now is, I can read in my template, but I cant add something which would not destroy the design. For example if I add "hello world" with the function:

body_add_par("Hello world!", style = "Normal") |>

The text appears but on the second page. Hopefully i dont have to change anything.

I dream of a solution which allows me to set something like:

"date"
"id" 
"logo" 

In my template and use a function in R to automatically change these information based on my data for the individual case.

With the result of a docx. "name_clinic_id_participat"

Until now I do the following:

I have a table with the patient IDs, the clinic Names and the dates.

These I want to inject in my template.

doc_2 <- read_docx(path = "C:/Users/Administrator/Desktop/Hiwi/Klinische & Psychotherapie/Teilnahmeerinnerung/2023-11-10/db-csv/template.docx") |>
  body_add_par("Hello world!", style = "Normal") |>

print(doc_2, target = "C:/Users/Administrator/Desktop/Hiwi/Klinische & Psychotherapie/Teilnahmeerinnerung/2023-11-10/db-csv/example_2.docx")

With this I can at least read in the template and receive it at the end again.

I really pray for help because there is a lot of pressure in my neck.

0

There are 0 best solutions below