我们正在开发一个Office任务窗格应用程序,用于搜索某些文本并用值替换它们。
例如,我们有一个word文档,如:
Total invoice of this year <<thisYear>> is <<totalInvoice>>
在任务窗格应用中,当用户点击按钮时,应用应搜索&lt;&lt;&gt;&gt;周围的文字,并将其替换为来自互联网数据的实际值。结果应如下所示:
Total invoice of this year 2015 is $2,000,078.34
我对Office任务窗格应用程序非常陌生,我应该怎么做?
==============更新=================
除了从MS运行演示之外,我什么都没做。该演示展示了如何从word文档中获取所选文本。这很容易理解。
function getDataFromSelection() {
Office.context.document.getSelectedDataAsync(Office.CoercionType.Text,
function (result) {
if (result.status === Office.AsyncResultStatus.Succeeded) {
app.showNotification('The selected text is:', '"' + result.value + '"');
} else {
app.showNotification('Error:', result.error.message);
}
}
);
}
但是,我没有找到任何Find
或Replace
API,但是这样:
Document API
Document object
bindings property
customXmlParts property
mode property
settings property
url property
addHandlerAsync method
getActiveViewAsync method
getFileAsync method
getFilePropertiesAsync method
getSelectedDataAsync method
goToByIdAsync method
removeHandlerAsync method
setSelectedDataAsync method
ActiveViewChanged event
SelectionChanged event
答案 0 :(得分:0)
根据MS documentation,您可以执行以下操作
适用于:内容和任务窗格应用类型
为了与Excel,PowerPoint和Word中的文档数据进行交互,API提供了Document对象。您可以使用Document对象成员从以下方式访问数据:
- 以文本形式读取和写入活动选择,连续 细胞(基质)或表格。
- 表格数据(矩阵或表格)。
- 绑定(使用&#34;添加&#34; Bindings对象的方法创建)。
- 自定义XML部件(仅适用于Word)。
- 文档上的每个应用程序都保留了设置或应用状态。
醇>
还低于它说
Document对象支持开发人员访问的四种方式 文件内容:
- 基于选择的访问
- 基于绑定的访问
- 自定义基于XML的部分访问(仅限Word)
- 整个基于文档的访问权限(仅限PowerPoint和Word)
醇>
在yet another documentation中,MS解释说选择是应用工作流程的关键部分。
我相信你唯一的路线是:
setSelectedDataAsync
方法运行替换代码。Document.getFileAsync
方法获取完整文档,并替换&lt;&lt; ..&gt;&gt;在代码中然后创建一个新文档。请参阅获取整个内容的示例here。