Instantly share code, notes, and snippets.
Last active
March 13, 2019 09:20
-
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 crazygao/ca1fc4b98002900b01be1f965e152892 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)); | |
$("#deleteHidden").click(() => tryCatch(deleteHidden)); | |
$("#hide").click(() => tryCatch(hide)); | |
$("#create").click(() => tryCatch(create)); | |
$("#veryhidden").click(() => tryCatch(veryhidden)); | |
$("#unveryhidden").click(() => tryCatch(unveryhidden)); | |
$("#deleteveryhidden").click(() => tryCatch(deleteveryhidden)); | |
$("#hideToVeryhidden").click(() => tryCatch(hideToVeryhidden)); | |
$("#VeryhiddenToHide").click(() => tryCatch(VeryhiddenToHide)); | |
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"); | |
hiddenSheet.visibility = "Hidden"; | |
} | |
await context.sync(); | |
}); | |
} | |
async function veryhidden() { | |
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"); | |
hiddenSheet.visibility = "VeryHidden"; | |
} else { | |
hiddenSheet.visibility = "VeryHidden"; | |
} | |
await context.sync(); | |
}); | |
} | |
async function unveryhidden() { | |
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.visibility = "Visible"; | |
} | |
await context.sync(); | |
}); | |
} | |
async function deleteveryhidden() { | |
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.delete(); | |
} | |
await context.sync(); | |
}); | |
} | |
async function deleteHidden() { | |
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.delete(); | |
} | |
await context.sync(); | |
}); | |
} | |
var deleteCreated2 = async (context) => { | |
var sheets = context.workbook.worksheets; | |
var hiddenSheet = sheets.getItemOrNullObject("Test1O"); | |
}; | |
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(); | |
}); | |
} | |
async function hideToVeryhidden() { | |
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 = "VeryHidden"; | |
} | |
await context.sync(); | |
}); | |
} | |
async function VeryhiddenToHide() { | |
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> | |
<b>Original Scenario:</b> In Win32/Mac Excel it works fine but Excel Online | |
sheetTabBar is still visible. 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> | |
<button id="deleteHidden" class="ms-Button"> | |
<span class="ms-Button-label">Demo A - Delete Hidden</span> | |
</button> | |
<p> | |
Very Hidden right click sheetTabBar should not be unhide | |
</p> | |
<button id="veryhidden" class="ms-Button"> | |
<span class="ms-Button-label">Create and VeryHidden</span> | |
</button> | |
<button id="unveryhidden" class="ms-Button"> | |
<span class="ms-Button-label">unVeryHidden</span> | |
</button> | |
<button id="deleteveryhidden" class="ms-Button"> | |
<span class="ms-Button-label">DeleteVeryHidden</span> | |
</button> | |
<p> | |
Analysis Cases, Change a sheet to different visibility and see sheetTabBar. | |
</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> | |
<button id="hideToVeryhidden" class="ms-Button"> | |
<span class="ms-Button-label">Demo B - Step3: Hide To Veryhidden</span> | |
</button> | |
<button id="VeryhiddenToHide" class="ms-Button"> | |
<span class="ms-Button-label">Demo B - Step4: Veryhidden To Hide</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