question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Replacing text in the whole document

See original GitHub issue

I’m trying to figure out if there is a way to replace some text in the entire document. So far I managed to successfully use this solution:

string xml = document._document.InnerXml;
document._document.InnerXml = xml.Replace("a", "b");
document.Save(false);

But this does it only in the document part (not in footers & headers). Is there a more “official” way to do this in the library? If not, what would be the day to do it? Thank you!

Issue Analytics

  • State:closed
  • Created 7 months ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
PrzemyslawKlyscommented, Mar 6, 2023

Yes and no. So I would expect someone searching for something like Your company value is 100,000$ and then a user who is actually playing with text formatting formats 10000 with bold and rest of the text with no formatting. And then you have to find 100k and replace it, but only if the full text is Your company value is 100,000$. In this case it would be two WordParagraphs or even more if they play a lot how it’s formatted. It’s a niche thing, but I can see that happening. So just leaving it as something to think about.

1reaction
MarianSWAcommented, Mar 6, 2023

I think it’s not worth implementing right now, it’s a very niche thing, and when someone actually needs it, it would be more easy when there are actually real world examples and expectations on how it should behave. For now, the FindAndReplace you implemented is more than enough, for the vast majority of cases, I think 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Find and replace text
Go to Home > Replace. · Enter the word or phrase you want to replace in Find what. · Enter your new text...
Read more >
MS Word Replace Text in Document - Activities
I am trying to replace excel data with an MS word placeholder and it fails if the middle name is unavailable. I have...
Read more >
Using Find & Replace in Microsoft Word - YouTube
... to quickly replace one word or phrase with another throughout your whole document. You can also use Find and Replace to change...
Read more >
How to Find and Replace Text in Word - Nira
Step #3 Select the Replace option located on the top-right-hand side of your screen. Alternatively, you can also press Ctrl + H. The...
Read more >
Word: Using Find and Replace
To replace text: · From the Home tab, click the Replace command. · The Find and Replace dialog box will appear. · Type...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found