Created
March 15, 2021 02:15
-
-
Save ci010/1056df011981d9d941194842e4cf6c63 to your computer and use it in GitHub Desktop.
Print Worksheet.TabId
This file contains 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: Worksheet.TabId | |
description: Print Worksheet.TabId | |
host: EXCEL | |
api_set: {} | |
script: | |
content: > | |
$("#run").click(() => tryCatch(getActiveWorksheet)); | |
$("#run1").click(() => tryCatch(getInputWorksheet)); | |
async function printTabId(ws: Excel.Worksheet, context: | |
Excel.RequestContext) { | |
ws.load("tabId"); | |
await context.sync(); | |
console.log(ws.tabId); | |
} | |
async function getActiveWorksheet() { | |
await Excel.run(async (context) => { | |
const ws = context.workbook.worksheets.getActiveWorksheet(); | |
await printTabId(ws, context); | |
}); | |
} | |
async function getInputWorksheet() { | |
await Excel.run(async (context) => { | |
const name = $("#name").val() as string; | |
const ws = context.workbook.worksheets.getItemOrNullObject(name); | |
ws.load("isNullObject"); | |
await context.sync(); | |
if (!ws.isNullObject) { | |
await printTabId(ws, context); | |
} else { | |
console.log("Cannot found sheet named " + name); | |
} | |
}); | |
} | |
/** 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=\"samples ms-font-m\">\n\t<h3>Print Worksheet Tab Id</h3>\n\t<button id=\"run\" class=\"ms-Button\">\n <span class=\"ms-Button-label\">Print Selected Worksheet Tab Id</span>\n </button>\n\t<div style=\"margin: 10px\">\n\t\tWorksheet Name\n <input id=\"name\">\n </div>\n\t\t<button id=\"run1\" class=\"ms-Button\">\n <span class=\"ms-Button-label\">Print Named Worksheet Tab Id</span>\n </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://unpkg.com/@microsoft/office-js@1.1.47-custom.6/dist/office.debug.js | |
// @types/office-js | |
https://appsforoffice.microsoft.com/lib/beta/hosted/office.js | |
@types/office-js | |
office-ui-fabric-js@1.4.0/dist/css/fabric.min.css | |
office-ui-fabric-js@1.4.0/dist/css/fabric.components.min.css | |
core-js@2.4.1/client/core.min.js | |
@types/core-js | |
jquery@3.1.1 | |
@types/jquery@3.3.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment