Last active
March 27, 2020 14:44
-
-
Save PramodKumarYadav/8a3f9c3fcd935033f88fa74f1ce5ea70 to your computer and use it in GitHub Desktop.
This add in collapses all rows to give you a high level reading view.
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: Collapse Rows | |
description: This add in collapses all rows to give you a high level reading view. | |
host: EXCEL | |
api_set: {} | |
script: | |
content: | | |
$("#collapseRows").click(() => tryCatch(run)); | |
async function run() { | |
await Excel.run(async (context) => { | |
const sheet = context.workbook.worksheets.getActiveWorksheet(); | |
var usedRange = sheet.getUsedRange(false); | |
usedRange.load("rowCount, format"); | |
await context.sync(); | |
var lastRow = usedRange.rowCount; | |
console.log("Total rowCount:" + lastRow); | |
var firstRow = $("#startRow").val(); | |
console.log("Starting row:" + firstRow); | |
var selectRange = sheet.getRange(firstRow + ":" + lastRow); | |
var height = $("#rowSize").val(); | |
console.log("desired row height:" + height); | |
selectRange.format.rowHeight = Number(height); | |
console.log("changed row height:" + selectRange.format.rowHeight); | |
}); | |
} | |
/** 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\t<p class=\"ms-font-m\">This sample demonstrates how to use this addin using Excel API calls.</p>\n</section>\n\n<section class=\"samples ms-font-m\">\n\t<h3>Try it out</h3>\n\t<p class=\"ms-font-m\">Go to the worksheet where you want to have a high level view and, then press button\n\t\t<b>Collapse Rows</b>.</p>\n\t<button id=\"collapseRows\" class=\"ms-Button\">\n <span class=\"ms-Button-label\">Collapse Rows</span>\n </button>\n\t<input type=\"number\" id=\"rowSize\" value=12>Enter Row height (default=12)</input>\n\t<br>\n\t<br>\n\t<input type=\"number\" id=\"startRow\" value=3>Specify Start Row (default=3)</input>\n\t<img src='https://laughtard.com/wp-content/uploads/2017/06/gif-12-4.gif'>\n</section>" | |
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/1/hosted/office.js | |
@types/office-js | |
[email protected]/dist/css/fabric.min.css | |
[email protected]/dist/css/fabric.components.min.css | |
[email protected]/client/core.min.js | |
@types/core-js | |
[email protected] | |
@types/[email protected] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment