How to replace character/text in document?

how can I replace character/text in document?

The thing is, I want to make an offline translation plugin.when I use the api " ReplaceTextSmart" ,it’s always disappointing,there are some formatting errors.

So I decided to translate it line by line,I take all the paragraphs, all the elements in the document, and then I go through all the text and translate it one by one.

But I couldn’t find a way to put my translated text in.

Is there a method like SetText(), or some other solution?

simplified Chinese to traditional Chinese

Hello @David

Have you tried using SearchAndRepalce() method for that purpose? It is available as:

Yes, thank you very much!
I have used this method to achieve the function today, but when the document is large, the execution efficiency is relatively low, of course, but also basically meet the needs.

1 Like

Can you provide more details on this? What kind of efficiency loss you are referring to?

I had a word document of about 60M, which contained some pictures and text. Then I called GetText() through paragraphs, elements, and got more than 3800 Chinese characters or short sentences that needed to be replaced, and then replaced these more than 3800 places. The execution time took about 30 minutes. My code looks like the official example “SearchAndRelace”

Thanks for the details. We can take a look at this situation, but for that we will need this document and macro sample that was executed to reproduce everything according to your scenario to analyze this delay.