JavaScript API for Office: How to get currently selected cell identifier?

99封情书 提交于 2019-12-25 02:14:57

问题


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.

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?


回答1:


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

  1. Add a binding to the region of the sheet you care about
  2. Add a change handler to that binding
  3. Call getSelectedDataAsync and store the value
  4. Call setSelectedDataAsync with some arbitrary string. This will trigger your change handler.
  5. In the change handler's callback, get the data for the binding
  6. Search for your string and calculate the identifier from its index
  7. Restore the data

Hope that helps, might be a little fragile though.

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



来源:https://stackoverflow.com/questions/22534850/javascript-api-for-office-how-to-get-currently-selected-cell-identifier

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!