Office的JavaScript API:如何获取当前选择的单元格标识符? [英] JavaScript API for Office: How to get currently selected cell identifier?

查看:83
本文介绍了Office的JavaScript API:如何获取当前选择的单元格标识符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得出的结论是,此功能目前在Office v1.1的JavaScript API中不可用,但我想先确定一下.

I've come to the conclusion that this functionality is not currently available in the JavaScript API for Office v1.1, but thought I'd just make sure here first.

我想获取当前所选单元格的标识符(即"A1"),但是在支持此功能的API中找不到任何内容.我觉得这很奇怪,因为这似乎是一个任意要求,而且您可以使用Document.goToByIdAsync方法的标识符来设置当前选择.

I would like to get the identifier (ie. "A1") of the currently selected cell, but cannot find anything in the API that supports this. I find it very odd as this seems to be a arbitrary requirement and as you can set the current selection using an identifier with the Document.goToByIdAsync method.

有人知道是否有访问此信息的方法吗?

Does anyone know if there is a method to access this information?

推荐答案

您可能会采用的一种骇人听闻的方法如下:

One hacky way you might be able to do it is as follows:

  1. 在您要关注的工作表区域添加绑定
  2. 向该绑定添加更改处理程序
  3. 调用getSelectedDataAsync并存储值
  4. 使用任意字符串调用setSelectedDataAsync.这将触发您的变更处理程序.
  5. 在更改处理程序的回调中,获取绑定的数据
  6. 搜索您的字符串并根据其索引计算标识符
  7. 还原数据

希望如此,但可能会有些脆弱.

Hope that helps, might be a little fragile though.

edit:看起来BindingSelectionChanged回调获得了一个带有位置信息的事件(startRow,startColumn,rowCount,columnCount),因此不需要上面的技巧:)

edit: It looks like the BindingSelectionChanged callback gets an event with position information (startRow, startColumn, rowCount, columnCount) so no need for the hack above :)

这篇关于Office的JavaScript API:如何获取当前选择的单元格标识符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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