Instantly share code, notes, and snippets.
Last active
February 27, 2019 12:18
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
-
Save lumine2008/01146cac8fc87f1f8ea954b116c45f19 to your computer and use it in GitHub Desktop.
Create a new snippet from a blank template.
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: Hidden Sheet | |
| description: Create a new snippet from a blank template. | |
| host: EXCEL | |
| api_set: {} | |
| script: | |
| content: | | |
| $("#run").click(() => tryCatch(run)); | |
| $("#hide").click(() => tryCatch(hide)); | |
| $("#create").click(() => tryCatch(create)); | |
| $("#runsync").click(() => tryCatch(runsync)); | |
| async function runsync() { | |
| await Excel.run(async (context) => { | |
| var sheets = context.workbook.worksheets; | |
| var hiddenSheet = sheets.getItemOrNullObject("Test3OCEAN_SETTINGS"); | |
| hiddenSheet.load(["name", "visibility", "isNullObject"]); | |
| await context.sync(); | |
| if (hiddenSheet.isNullObject) { | |
| hiddenSheet = sheets.add("Test3OCEAN_SETTINGS"); | |
| await context.sync(); | |
| hiddenSheet.visibility = "Hidden"; | |
| } | |
| await context.sync(); | |
| }); | |
| } | |
| async function run() { | |
| await Excel.run(async (context) => { | |
| var sheets = context.workbook.worksheets; | |
| var hiddenSheet = sheets.getItemOrNullObject("Test1OCEAN_SETTINGS"); | |
| hiddenSheet.load(["name", "visibility", "isNullObject"]); | |
| await context.sync(); | |
| if (hiddenSheet.isNullObject) { | |
| hiddenSheet = sheets.add("Test1OCEAN_SETTINGS"); | |
| //await context.sync(); | |
| hiddenSheet.visibility = "Hidden"; | |
| } | |
| await context.sync(); | |
| }); | |
| } | |
| async function create() { | |
| await Excel.run(async (context) => { | |
| var sheets = context.workbook.worksheets; | |
| var hiddenSheet = sheets.getItemOrNullObject("Test2OCEAN_SETTINGS"); | |
| hiddenSheet.load(["name", "visibility", "isNullObject"]); | |
| await context.sync(); | |
| if (hiddenSheet.isNullObject) { | |
| hiddenSheet = sheets.add("Test2OCEAN_SETTINGS"); | |
| } | |
| await context.sync(); | |
| }); | |
| } | |
| async function hide() { | |
| await Excel.run(async (context) => { | |
| var sheets = context.workbook.worksheets; | |
| var hiddenSheet = sheets.getItemOrNullObject("Test2OCEAN_SETTINGS"); | |
| hiddenSheet.load(["name", "visibility", "isNullObject"]); | |
| await context.sync(); | |
| if (!hiddenSheet.isNullObject) { | |
| hiddenSheet.visibility = "Hidden"; | |
| } | |
| 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: | | |
| <p> | |
| In Win32 Excel it works fine but Excel Online doesn't really hide the hidden sheet after | |
| creation. Only after a refresh (F5) the sheet is hidden. | |
| </p> | |
| <button id="run" class="ms-Button"> | |
| <span class="ms-Button-label">Demo A - Run</span> | |
| </button> | |
| <p> | |
| However, if run step by step, it works. | |
| </p> | |
| <button id="create" class="ms-Button"> | |
| <span class="ms-Button-label">Demo B - Step1: Create</span> | |
| </button> | |
| <button id="hide" class="ms-Button"> | |
| <span class="ms-Button-label">Demo B - Step2: Hide</span> | |
| </button> | |
| <p> | |
| A workaround is call sync() before hide | |
| </p> | |
| <button id="runsync" class="ms-Button"> | |
| <span class="ms-Button-label">Demo C - Run sync</span> | |
| </button> | |
| 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 | |
| @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