Skip to content
This repository was archived by the owner on Aug 1, 2019. It is now read-only.

[ARCHIVED] This sample add-in shows how to detect when the selection changes in a table (matrix) in Excel 2013, and then how to display the table columns and rows included in the selection.

License

Notifications You must be signed in to change notification settings

OfficeDev/Excel-Add-in-JavaScript-GetSelectionChangeCoordinates

Repository files navigation

[ARCHIVED] Excel add-in: Get selection-change coordinates in an Excel table

Note: This repo is archived and no longer actively maintained. Security vulnerabilities may exist in the project, or its dependencies. If you plan to reuse or run any code from this repo, be sure to perform appropriate security checks on the code or dependencies first. Do not use this project as the starting point of a production Office Add-in. Always start your production code by using the Office/SharePoint development workload in Visual Studio, or the Yeoman generator for Office Add-ins, and follow security best practices as you develop the add-in.

Table of contents

##Summary This sample add-in shows how to detect when the selection changes in a table (matrix) in Excel 2013, and then how to display the table columns and rows included in the selection.

Prerequisites

This sample requires the following:

  • Visual Studio 2013 with Update 5 or Visual Studio 2015.
  • Excel 2013
  • Internet Explorer 9 or later, which must be installed but doesn't have to be the default browser. To support Office Add-ins, the Office client that acts as host uses browser components that are part of Internet Explorer 9 or later.
  • One of the following as the default browser: Internet Explorer 9, Safari 5.0.6, Firefox 5, Chrome 13, or a later version of one of these browsers.
  • Familiarity with JavaScript programming and web services.

Key components of the sample

The sample solution contains the following files:

  • DisplayExcelSelectionCoordinatesManifest.xml: The manifest file for the Excel add-in.
  • App\Home\Home.html: The HTML user interface for the Excel add-in.
  • App\Home\Home.js.

##Description of the code

This add-in opens a blank Excel 2013 file. The user must first enter values in a contiguous rectangular collection of cells, thereby creating a table (matrix); enter values in the table; and then select the table. When the user then chooses Set Binding, the app binds to that table.

Choosing Set Binding executes the bindNamedItem function, in the Home.js file. This function uses the addFromSelectionAsync method of the Bindings object of the JavaScript API for Office to create a new binding of coercion type "matrix." The function then calls the addEventHandler function, which uses the getByIdAsync method of the Bindings object to identify the binding by its ID ("myMatrix") and add a handler for the bindingSelectionChanged event of the Binding object to the binding. Then, when the user makes a new selection in the table, the event handler uses the startRow, startColumn, columnCount, and rowCount properties of the BindingSelectionChangedEventArgs object to display information about the new selection in the task pane.

Build and debug

  1. Open the solution in Visual Studio. Press F5 to build and deploy the sample add-in and open it in Excel 2013.
  2. Create a table by entering values in several contiguous cells occupying at least three rows and three columns.
  3. Select the entire table.
  4. In the add-in task pane, choose Set Binding.
  5. Select one or more contiguous cells in the table.

##Troubleshooting

If the app fails to respond as described, try reloading it. (In the task pane, choose the down arrow, and then choose the Reload button.)

##Questions and comments##

  • If you have any trouble running this sample, please log an issue.
  • Questions about Office Add-in development in general should be posted to Stack Overflow. Make sure that your questions or comments are tagged with [office-addins].

Additional resources

Copyright

Copyright (c) 2015 Microsoft. All rights reserved.

About

[ARCHIVED] This sample add-in shows how to detect when the selection changes in a table (matrix) in Excel 2013, and then how to display the table columns and rows included in the selection.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 5

Languages