在C#中的Word文档中替换文本框 [英] replace textbox in word documents in c#

查看:260
本文介绍了在C#中的Word文档中替换文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我有一个Word 2007文档,我的Word文档具有4个文本框控件,我想用c#中的我的应用中的输入字符串替换这些文本框,请注意,我不想替换word中的文本类型,我想替换Word文档的文本框控件;



 FindAndReplace(varWord, @" ,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中的文本框控件中工作的代码.请帮助我

解决方案

嗨 我认为您想删除Word文档中的文本框并在其中写入一些文本.
您可以使用

 ActiveDocument.Shapes(" ).选择
Selection.ShapeRange.删除 



然后在那写你的文字...

希望对您有帮助.


hi i 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

解决方案

Hi I think you want to delete textbox in word document and write some text there.
You can do that using

ActiveDocument.Shapes("Text Box 2").Select
Selection.ShapeRange.Delete



and then write your text there...

Hope this will help you.


这篇关于在C#中的Word文档中替换文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆