VSTO 中的插件 - 如何使用带按钮的功能区从 Word 文档中获取文本 [英] add-in in VSTO - How to get text from Word document using Ribbon with button

查看:38
本文介绍了VSTO 中的插件 - 如何使用带按钮的功能区从 Word 文档中获取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 word 插件中的按钮对 word 文档中的文本进行处理?我不知道点击按钮后如何从文档中获取文本,因为在 Ribbon 类中无法访问应用程序.

How can I do something with text in my word document using button in word add-in? I don't know, how to get text from document after click on the button, because Application is not accessible in Ribbon class.

推荐答案

以下代码应采用在选择中找到的文本:

The following code should take the text found in the selection:

string textFromDoc;
textFromDoc = Globals.ThisAddIn.Application.Selection.Text;

您还可以通过以下方式指定Range:

You can also specify the Range by:

textFromDoc = Globals.ThisAddIn.Application.ActiveDocument.Range(0, 20).Text;

这将采用活动文档中的前 20 个字母.最重要的是,您可以使用以下方式访问应用程序:

This will take the first 20 letters written in the active document. Bottom line, you can access Application by using:

Globals.ThisAddIn.Application

这篇关于VSTO 中的插件 - 如何使用带按钮的功能区从 Word 文档中获取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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