C # Replace the content in the Word text box (do not use Bookmark)

Source: Internet
Author: User

For more information, see StoryRanges, NextStoryRange, WdStoryType, and Range.

Replace text in Word textbox objects using VSTO and C #

01 /// <summary> 02 /// Search for and replace the text 03 /// </summary> 04 /// <param name="wordApp"></param> 05 /// <param name="oldStr"></param> 06 /// <param name="newStr"></param> 07 public void SearchReplace( string oldStr, string newStr) 08 { 09      # Region text area 10      object replaceAll = WdReplace.wdReplaceAll; 11   12      wordApp.Selection.Find.ClearFormatting(); 13      wordApp.Selection.Find.Text = oldStr; 14   15      wordApp.Selection.Find.Replacement.ClearFormatting(); 16      wordApp.Selection.Find.Replacement.Text = newStr; 17   18      wordApp.Selection.Find.Execute( 19          ref missing, ref missing, ref missing, ref missing, ref missing, 20          ref missing, ref missing, ref missing, ref missing, ref missing, 21          ref replaceAll, ref missing, ref missing, ref missing, ref missing); 22      #endregion 23   24      # Region text box 25      StoryRanges sr = wordDoc.StoryRanges; 26
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.