Skip to content

Instantly share code, notes, and snippets.

@chenxizhang
Last active March 13, 2019 09:50
Show Gist options
  • Save chenxizhang/1dc3f6f7608b3fbb50e830ef47704671 to your computer and use it in GitHub Desktop.
Save chenxizhang/1dc3f6f7608b3fbb50e830ef47704671 to your computer and use it in GitHub Desktop.
name: GetAPIValues
description: ''
host: EXCEL
api_set: {}
script:
content: |
$("#run").click(() => tryCatch(run));
async function run() {
await Excel.run(async (context) => {
console.log("get json");
await $.get("https://webaddinapisample.azurewebsites.net/api/values")
.done(async function(result) {
var sheet = context.workbook.worksheets.getActiveWorksheet();
var range = sheet.getRange("A1:B1");
range.values = [result];
await context.sync();
})
.fail(function(jqXHR, textStatus, errorThrown) {
console.log(errorThrown);
});
});
}
/** 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="run" class="ms-Button">
<span class="ms-Button-label">Run</span>
</button>
language: html
style:
content: "/* Your style goes here */\r\n"
language: css
libraries: |
https://appsforoffice.microsoft.com/lib/1/hosted/office.js
https://appsforoffice.microsoft.com/lib/1/hosted/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
@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
name: GetAPIValues
description: ''
author: chenxizhang
host: EXCEL
api_set: {}
script:
content: |
$("#run").click(() => tryCatch(run));
async function run() {
await Excel.run(async (context) => {
console.log("get json");
await $.get("https://webaddinapisample.azurewebsites.net/api/values").done(async function (result) {
var sheet = context.workbook.worksheets.getActiveWorksheet();
var range = sheet.getRange("A1:B1");
range.values = [result];
await context.sync();
}).fail(function (jqXHR, textStatus, errorThrown) {
console.log(errorThrown);
});
});
}
/** 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="run" class="ms-Button">
<span class="ms-Button-label">Run</span>
</button>
language: html
style:
content: "/* Your style goes here */\r\n"
language: css
libraries: |
https://appsforoffice.microsoft.com/lib/1/hosted/office.js
https://appsforoffice.microsoft.com/lib/1/hosted/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
@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
name: 获取远程数据
description: ''
host: EXCEL
api_set: {}
script:
content: |
$("#run").click(() => tryCatch(run));
async function run() {
await Excel.run(async (context) => {
console.log("get json");
await $.get("https://webaddinapisample.azurewebsites.net/api/values")
.done(async function(result) {
var sheet = context.workbook.worksheets.getActiveWorksheet();
var range = sheet.getRange("A1:B1");
range.values = [result];
await context.sync();
})
.fail(function(jqXHR, textStatus, errorThrown) {
console.log(errorThrown);
});
});
}
/** 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="run" class="ms-Button">
<span class="ms-Button-label">Run</span>
</button>
language: html
style:
content: "/* Your style goes here */\r\n"
language: css
libraries: |
https://appsforoffice.microsoft.com/lib/1/hosted/office.js
https://appsforoffice.microsoft.com/lib/1/hosted/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
@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment