Created
February 27, 2019 10:21
-
-
Save lumine2008/e692f01c38894d61a5e01cf3c7ff3b7d to your computer and use it in GitHub Desktop.
Gets and sets the currently selected range.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: SelectedRangeSize | |
| description: Gets and sets the currently selected range. | |
| host: EXCEL | |
| api_set: {} | |
| script: | |
| content: | | |
| $("#get-selection").click(() => tryCatch(getSelection)); | |
| $("#set-selection").click(() => tryCatch(setSelection)); | |
| $("#get-position").click(() => tryCatch(getPosition)); | |
| async function getPosition() { | |
| await Excel.run(async (context) => { | |
| const range = context.workbook.getSelectedRange(); | |
| range.load("address"); | |
| let cellsInRange=range.getCellProperties({format:{rowHeight:true} }); | |
| await context.sync(); | |
| console.log(JSON.stringify(cellsInRange)); | |
| //context.workbook.worksheets | |
| console.log(`The address of the selected range is "${range.address}"`); | |
| }); | |
| } | |
| async function getSelection() { | |
| await Excel.run(async (context) => { | |
| const range = context.workbook.getSelectedRange(); | |
| range.load("address"); | |
| await context.sync(); | |
| console.log(`The address of the selected range is "${range.address}"`); | |
| }); | |
| } | |
| async function setSelection() { | |
| await Excel.run(async (context) => { | |
| const sheet = context.workbook.worksheets.getActiveWorksheet(); | |
| const range = sheet.getRange("B2:E6"); | |
| range.select(); | |
| await context.sync(); | |
| }); | |
| } | |
| /** Default helper for invoking an action and handling errors. */ | |
| async function tryCatch(callback) { | |
| try { | |
| await callback(); | |
| } catch (error) { | |
| // Note: In a production add-in, you'd want to notify the user through your add-in's UI. | |
| console.error(error); | |
| } | |
| } | |
| language: typescript | |
| template: | |
| content: "<section class=\"ms-font-m\">\n <p>This sample shows how to get and set the currently selected range.</p>\n</section>\n\n<section class=\"samples ms-font-m\">\n <h3>Try it out</h3>\n <button id=\"get-selection\" class=\"ms-Button\">\n <span class=\"ms-Button-label\">Get selection</span>\n </button> \n <button id=\"set-selection\" class=\"ms-Button\">\n <span class=\"ms-Button-label\">Set selection</span>\n </button>\n \t<button id=\"get-position\" class=\"ms-Button\">\n\t <span class=\"ms-Button-label\">Get Position</span>\n\t </button>\n</section>\n" | |
| language: html | |
| style: | |
| content: | | |
| section.samples { | |
| margin-top: 20px; | |
| } | |
| section.samples .ms-Button, section.setup .ms-Button { | |
| display: block; | |
| margin-bottom: 5px; | |
| margin-left: 20px; | |
| min-width: 80px; | |
| } | |
| language: css | |
| libraries: | | |
| https://appsforoffice.microsoft.com/lib/beta/hosted/office.js | |
| https://appsforoffice.microsoft.com/lib/beta/hosted/office.d.ts | |
| [email protected]/dist/css/fabric.min.css | |
| [email protected]/dist/css/fabric.components.min.css | |
| [email protected]/client/core.min.js | |
| @types/core-js | |
| @microsoft/[email protected]/dist/office.helpers.min.js | |
| @microsoft/[email protected]/dist/office.helpers.d.ts | |
| [email protected] | |
| @types/[email protected] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment