问题
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:
- Add a binding to the region of the sheet you care about
- Add a change handler to that binding
- Call getSelectedDataAsync and store the value
- Call setSelectedDataAsync with some arbitrary string. This will trigger your change handler.
- In the change handler's callback, get the data for the binding
- Search for your string and calculate the identifier from its index
- 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