使用Windows窗体将文本添加到Word文档中的richtextcontentcontrol [英] Using Windows Form to add text to richtextcontentcontrol in Word document

查看:195
本文介绍了使用Windows窗体将文本添加到Word文档中的richtextcontentcontrol的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在构建一个项目,我想在其中添加文本到富文本内容控件中单击随机窗体上的按钮。

I'm building a project in which I want to add text to a richtextcontentcontrol in word by clicking a button on a random windows form.

我想将文本"传递"到word文档,该文档将添加到Visual Studio的项目中。

I want to 'pass' de text to the word document, which is added in the project in Visual Studio.

在提供的链接中,包含文件。

In the provided link, the documents are included.

https://www.dropbox.com/sh/kwhevbxyvn0ic77/AACXF1qW12vVlGuCXMDFqj-la?dl=0

https://www.dropbox.com/sh/kwhevbxyvn0ic77/AACXF1qW12vVlGuCXMDFqj-la?dl=0

提前致谢!

推荐答案

您好,

我有下载了你的项目,但我仍然想知道你如何在项目中使用该表格?

I have downloaded your project but I'm still wondering how do you use the form in the project?

我认为这个过程是获取文本 - >获取控制对象 - >设置文本到控件对象,对吗? 哪个部分代码让你感到困惑?

I think the process is Getting the text->Getting the control object->Setting the text to the control object, right? Which part code puzzles you?

我认为关键点可能是如何访问richtextcontentcontrol。如果是这样,我建议你为控件设置一个标签,例如"Test"。然后你可以使用

SelectContentControlByTag
返回对象然后将文本设置为对象的方法。

I think the key point maybe how to access the richtextcontentcontrol. If so, I would suggest you set a tag for the control, such as "Test". And then you could use SelectContentControlByTag method to return the object and then set text to the object.

这是一个简单的代码。

//not sure how would you get the document object, you could get it by your way
	    Word.Document wdDoc = Globals.ThisDocument.Application.ActiveDocument;
            Word.ContentControl contentControl = wdDoc.SelectContentControlsByTag("Test")[1];
            contentControl.Range.Text = "This is added text string";

最好的问候,

Terry


这篇关于使用Windows窗体将文本添加到Word文档中的richtextcontentcontrol的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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