Created
January 23, 2019 08:16
-
-
Save jipyua/65fa247c5ca4850034d29a689302e98c to your computer and use it in GitHub Desktop.
Create a new snippet from a blank template.
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: SaveClose (1) | |
description: Create a new snippet from a blank template. | |
host: EXCEL | |
api_set: {} | |
script: | |
content: | | |
$("#save").click(() => tryCatch(save)); | |
$("#close").click(() => tryCatch(close)); | |
$("#autosave").click(() => tryCatch(autoSave)); | |
$("#previouslysaved").click(() => tryCatch(previouslySaved)); | |
$("#registerautosaveevent").click(() => tryCatch(registerAutoSave)); | |
$("#unregisterautosaveevent").click(() => tryCatch(unRegisterAutoSave)); | |
async function save() { | |
await Excel.run(async (context) => { | |
context.workbook.save(Excel.SaveBehavior.Save); | |
await context.sync(); | |
console.log("Save Success"); | |
}); | |
} | |
async function close() { | |
await Excel.run(async (context) => { | |
context.workbook.close(Excel.CloseBehavior.SkipSave); | |
await context.sync(); | |
console.log("Close Success"); | |
}); | |
} | |
async function autoSave() { | |
await Excel.run(async (context) => { | |
const workbook = context.workbook; | |
workbook.load("autoSave"); | |
await context.sync(); | |
console.log("Workbook AutoSave On?: " + workbook.autoSave); | |
}); | |
} | |
async function previouslySaved() { | |
await Excel.run(async (context) => { | |
const workbook = context.workbook; | |
workbook.load("previouslySaved"); | |
await context.sync(); | |
console.log("Workbook PreviouslySaved Status: " + workbook.previouslySaved); | |
}); | |
} | |
var autosaveEventResult; | |
async function registerAutoSave() { | |
await Excel.run(async (context) => { | |
autosaveEventResult = context.workbook.onAutoSaveSettingChanged.add(onSettingChanged); | |
await context.sync(); | |
console.log("AutoSave Setting Changed Event Registered."); | |
}); | |
} | |
async function unRegisterAutoSave() { | |
await Excel.run(autosaveEventResult.context, async (context) => { | |
autosaveEventResult.remove(); | |
await context.sync(); | |
console.log("AutoSave Setting Changed Event UnRegistered."); | |
}); | |
} | |
async function onSettingChanged() { | |
await Excel.run(async (context) => { | |
const workbook = context.workbook; | |
workbook.load("autoSave"); | |
await context.sync(); | |
console.log("AutoSave Setting Changed to: " + workbook.autoSave); | |
}); | |
} | |
/** 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: |- | |
<button id="save" class="ms-Button"> | |
<span class="ms-Button-label">Save</span> | |
</button> | |
<p></p> | |
<button id="close" class="ms-Button"> | |
<span class="ms-Button-label">Close</span> | |
</button> | |
<p></p> | |
<button id="autosave" class="ms-Button"> | |
<span class="ms-Button-label">Get AutoSave Status</span> | |
</button> | |
<p></p> | |
<button id="previouslysaved" class="ms-Button"> | |
<span class="ms-Button-label">Get PreviouslySaved Status</span> | |
</button> | |
<p></p> | |
<button id="registerautosaveevent" class="ms-Button"> | |
<span class="ms-Button-label">Register AutoSave Setting Changed Event</span> | |
</button> | |
<p></p> | |
<button id="unregisterautosaveevent" class="ms-Button"> | |
<span class="ms-Button-label">UnRegister AutoSave Setting Changed Event</span> | |
</button> | |
<p></p> | |
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 | |
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 | |
@microsoft/office-js-helpers@0.7.4/dist/office.helpers.min.js | |
@microsoft/office-js-helpers@0.7.4/dist/office.helpers.d.ts | |
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