Is there 开发者_如何学JAVAa way to replace the nth (given occurrence) of a text in MS Word document using C#'s
Application.Selection.Find.Execute
Method?
No, that method alone cannot accomplish your goal as it only allows all, none, or first replacement. But the API suite is total is more than powerful enough to do what you want to do, you just have to fiddle with it until you find the right API calls to get what you want.
Here are some important documents:
- Working with Text in Documents
- How to: Search for Text in Documents
- How to: Loop Through Found Items in Documents
The first link is the overview. In particular, you need to combine the calls in the second two to do what you want: loop using a search, stop and do a replace and the selected text at your desired occurrence. Using a new complex API can be difficult but use the examples and search for API methods for similar code to get ideas.
精彩评论