Last active
March 13, 2019 11:09
-
-
Save crazygao/17f6b5ac5ef210d23a6082da8c16d10d to your computer and use it in GitHub Desktop.
Performs a basic Excel API call using TypeScript.
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: Very Hide and Delete | |
description: Performs a basic Excel API call using TypeScript. | |
host: EXCEL | |
api_set: {} | |
script: | |
content: | | |
$("#VeryHide").click(() => tryCatch(run)); | |
$("#DelVeryHide").click(() => tryCatch(delIt)); | |
$("#CopyVeryHide").click(() => tryCatch(CopyIt)); | |
$("#UnhideAll").click(() => tryCatch(unhide)); | |
async function unhide() { | |
await Excel.run(async (context) => { | |
var sheets = context.workbook.worksheets; | |
sheets.load("items/visibility"); | |
await context.sync(); | |
sheets.items.forEach(function(item) { | |
item.visibility = "Visible"; | |
console.log(item.visibility); | |
}); | |
await context.sync(); | |
}); | |
} | |
async function run() { | |
await Excel.run(async (context) => { | |
var sheets = context.workbook.worksheets; | |
sheets.load("items/visibility"); | |
await context.sync(); | |
sheets.items.forEach(function(item, index) { | |
if (index == 0) { | |
item.visibility = "VeryHidden"; | |
} | |
console.log(item.visibility); | |
}); | |
}); | |
} | |
async function delIt() { | |
await Excel.run(async (context) => { | |
const range = context.workbook.getSelectedRange(); | |
console.log(context.workbook.properties); | |
var sheets = context.workbook.worksheets; | |
sheets.load("items/visibility"); | |
await context.sync(); | |
sheets.items.forEach(function(item) { | |
console.log(item.visibility); | |
if (item.visibility == "VeryHidden") { | |
item.delete(); | |
} | |
}); | |
range.format.fill.color = "yellow"; | |
range.load("address"); | |
await context.sync(); | |
console.log(`The range address was "${range.address}".`); | |
}); | |
} | |
async function CopyIt() { | |
await Excel.run(async (context) => { | |
const range = context.workbook.getSelectedRange(); | |
console.log(context.workbook.properties); | |
var sheets = context.workbook.worksheets; | |
sheets.load("items/visibility"); | |
await context.sync(); | |
sheets.items.forEach(function (item) { | |
console.log(item.visibility); | |
if (item.visibility == "VeryHidden") { | |
item.copy(Excel.WorksheetPositionType.beginning); | |
} | |
}); | |
range.format.fill.color = "yellow"; | |
range.load("address"); | |
await context.sync(); | |
console.log(`The range address was "${range.address}".`); | |
}); | |
} | |
/** Default helper for invoking an action and handling errors. */ | |
async function tryCatch(callback) { | |
try { | |
await callback(); | |
} catch (error) { | |
OfficeHelpers.UI.notify(error); | |
OfficeHelpers.Utilities.log(error); | |
} | |
} | |
language: typescript | |
template: | |
content: "<section class=\"ms-font-m\">\n\t<p class=\"ms-font-m\">This sample demonstrates delete veryhidden sheet should be blocked</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\">\n\t\t<ol>\n\t\t\t<li>Create a new worksheet and click <b>Veryhide</b>.</li>\n\t\t\t<li>Click <b>delete unhide/copy unhide</b> should give you an General Exception.</li>\n\t\t</ol>\n\t</p>\n <button id=\"VeryHide\" class=\"ms-Button\">\n <span class=\"ms-Button-label\">Veryhide</span>\n </button>\n\t\t<button id=\"DelVeryHide\" class=\"ms-Button\">\n\t\t <span class=\"ms-Button-label\">delete unhide</span>\n\t\t</button>\n\t\t<button id=\"CopyVeryHide\" class=\"ms-Button\">\n\t\t <span class=\"ms-Button-label\">copy unhide</span>\n\t\t</button>\n\t\t<button id=\"UnhideAll\" class=\"ms-Button\">\n\t\t\t\t<span class=\"ms-Button-label\">unhide all</span>\n\t\t</button>\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/beta/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 | |
@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