C
C
CryptoPython2018-05-20 18:24:53
C++ / C#
CryptoPython, 2018-05-20 18:24:53

How to replace multiple variables in word using c#?

When entering variables into the Word like: {name} - the program replaces {name} with the entered name in the textbox, but if there are several of these variables {name} in the file, then it changes only 1, how to make the program change all variables with the name {name}?
Code example:
varname = textBox1.Text;
ReplaceWordStub("{name}", name, ref wordDocument);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
GranD1K, 2018-05-20
@GranD1K

Work with the document using the Open XML SDK.
Here is an example, replacing text in a file.

A
Alexander Yudakov, 2018-05-20
@AlexanderYudakov

Find.Replace = wdReplaceAll; // значение константы: 2

Example:
www.askit.ru/custom/vba_office/m10/10_06_05_word_f...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question