本文介绍了在C#中的Word文档中替换文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨我有一个Word 2007文档,我的Word文档具有4个文本框控件,我想用c#中的我的应用中的输入字符串替换这些文本框,请注意,我不想替换word中的文本类型,我想替换Word文档的文本框控件;FindAndReplace(varWord, @" #Sabbat_School#" ,Properties.Settings .Default.SchoolName); 私有 无效 FindAndReplace(Word.Application wordApp, 对象 findText,对象 replaceText) { 对象 matchCase = true ; 对象 matchWholeWord = true ; 对象 matchWildCards = false ; 对象 matchSoundsLike = false ; 对象 matchAllWordForms = false ; 对象 forward = true ; 对象 format = true ; 对象 matchKashida = true ; 对象 matchDiacritics = true ; 对象 matchAlefHamza = true ; 对象 matchControl = true ; 对象 read_only = false ; 对象可见= 真; 对象 replace = 2 ; 对象 wrap = 1 ; wordApp.Selection.Find.Execute( ref findText, ref matchCase, ref matchWholeWord, ref matchWildCards, ref matchSoundsLike , ref matchAllWordForms, ref 向前, ref 包装,参考格式, ref replaceText, ref 替换, ref matchKashida , 参考 matchDiacritics, ref matchAlefHamza, ref matchControl); }
此代码将Word文档中的#Sabbat_School#替换为Properties.Settings.Default.SchoolName,但它替换了文本,并且在Word中的文本框控件中不起作用,
我想要一个在Word中的文本框控件中工作的代码.请帮助我
解决方案
hii have a word 2007 document , my word document have 4 text box control, i want to replace these text boxes with input strings in My apllication in c#,attention this ,i do not want to replace text type in word, i want to replace text box control of word document;
FindAndReplace(varWord, @"#Sabbat_School#", Properties.Settings.Default.SchoolName); private void FindAndReplace(Word.Application wordApp, object findText, object replaceText) { object matchCase = true; object matchWholeWord = true; object matchWildCards = false; object matchSoundsLike = false; object matchAllWordForms = false; object forward = true; object format = true; object matchKashida = true; object matchDiacritics = true; object matchAlefHamza = true; object matchControl = true; object read_only = false; object visible = true; object replace = 2; object wrap = 1; wordApp.Selection.Find.Execute(ref findText, ref matchCase, ref matchWholeWord, ref matchWildCards, ref matchSoundsLike, ref matchAllWordForms, ref forward, ref wrap, ref format, ref replaceText, ref replace, ref matchKashida, ref matchDiacritics, ref matchAlefHamza, ref matchControl); }
this code is replace #Sabbat_School# to Properties.Settings.Default.SchoolName in word documents , but it replace text and does not work in text box control in word,
i want a code that work in text box control in word. please help me
解决方案
这篇关于在C#中的Word文档中替换文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!