无法以编程方式在ms字中的文本框内插入文本 [英] could not insert text inside textbox in ms word programably

查看:91
本文介绍了无法以编程方式在ms字中的文本框内插入文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hellow
我想在以ms字创建的文本框中写入文本(可通过c#编程)

hellow
i want to write a text inside a textbox that i have created in ms word(programably by c#)

xShape  = oDataDoc.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, 1, 1, 75, 50, ref rng);
object ss2=(object)xShape;
xShape.Select(ref ss2);


使用上面的代码,我必须关闭c#程序才能使wordbox中的文本框处于活动状态,以便我可以在其中写入文本

我必须在文档上的任意位置按鼠标才能激活它
但是可能是另一种解决方案
如果我可以使用


using the above code i had to close my c# program in order to make the textbox active in word document so i can write my text inside it
OR
i have to press in the mouse anywhere on the document in order to make it active
BUT MAY BE ANOTHER SOLUTION
if i could insert a bookmark(B1) inside this textbox using

book1 = oDataDoc.Bookmarks.Add("B1", ref ss2);//<--- did not worked i get type mismatch


第二个参数是我的问题,如何获得文本框的范围?


the 2nd paramter is my problem, how could i get range of the textbox ?

推荐答案

我找到了解决方法
i have found the solution
xShape = YourDocument.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, 1, 1, 75, 50, ref rng);//.Name;
xShape.TextFrame.TextRange.Text = "Code Project";


这篇关于无法以编程方式在ms字中的文本框内插入文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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