Last active
July 2, 2021 07:24
-
-
Save ci010/d9af5deb67dbb2c4b3d345e815a17358 to your computer and use it in GitHub Desktop.
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: '' | |
host: EXCEL | |
api_set: {} | |
script: | |
content: | | |
$("#printCurrent").click(() => tryCatch(printCurrent)); | |
$("#printTarget").click(() => tryCatch(printTarget)); | |
async function printCurrent() { | |
await Excel.run(async (context) => { | |
const worksheet = context.workbook.worksheets.getActiveWorksheet(); | |
worksheet.load("tabId"); | |
await context.sync(); | |
console.log(worksheet.tabId); | |
}); | |
} | |
async function printTarget() { | |
await Excel.run(async (context) => { | |
const worksheet = context.workbook.worksheets.getItem($("#worksheet").val() as string); | |
worksheet.load("tabId"); | |
await context.sync(); | |
console.log(worksheet.tabId); | |
}); | |
} | |
/** 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: "<div>\n\t<div>\n\t\tCurrent Worksheet\n\t\t<button id=\"printCurrent\" class=\"ms-Button\">\n\t\t\t\t<span class=\"ms-Button-label\">Print Tab Id</span>\n\t\t</button>\n\t</div>\n\t<div style=\"margin-top: 10px\">\n\t\t<input id=\"worksheet\" placeholder=\"Worksheet Name\" />\n\t\t<button id=\"printTarget\" class=\"ms-Button\">\n\t\t\t\t<span class=\"ms-Button-label\">Print Tab Id</span>\n\t\t</button>\n\t</div>\n</div>" | |
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; | |
} | |
.ms-Button { | |
margin-left: 20px; | |
} | |
language: css | |
libraries: | | |
https://appsforoffice.microsoft.com/lib/beta/hosted/office.js | |
@types/office-js | |
// https://unpkg.com/@microsoft/office-js@1.1.71-custom.25/dist/office.js | |
// https://unpkg.com/@microsoft/office-js@1.1.71-custom.25/dist/office.d.ts | |
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