Created
August 23, 2018 23:24
-
-
Save Zlatkovsky/1b12ff3474063b6594b17a3b0d44c3c1 to your computer and use it in GitHub Desktop.
Shared with Script Lab
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: Get all charts on workbook | |
description: '' | |
author: Zlatkovsky | |
host: EXCEL | |
api_set: {} | |
script: | |
content: | | |
// Remember to include: | |
// lodash | |
// @types/lodash | |
// in the libraries tab! | |
// https://lodash.com/docs/4.17.10#flattenDeep | |
$("#run").click(() => tryCatch(run)); | |
async function run() { | |
await Excel.run(async (context) => { | |
context.workbook.worksheets.load({ | |
charts: { | |
worksheet: { | |
name: true | |
}, | |
name: true | |
} | |
}); | |
await context.sync(); | |
let charts: Excel.Chart[] = _.flattenDeep( | |
context.workbook.worksheets.items | |
.map(ws => ws.charts.items)); | |
charts.map(item => { | |
console.log(item.name); | |
console.log(item.worksheet.name); | |
}) | |
}); | |
} | |
/** 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 */ | |
language: css | |
libraries: | | |
https://appsforoffice.microsoft.com/lib/1/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 | |
lodash | |
@types/lodash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment