Skip to content

Instantly share code, notes, and snippets.

@MiaofeiWang
Last active June 11, 2018 06:00
Show Gist options
  • Save MiaofeiWang/c3f3d9227809f2a29f4f5fcb6711f0ef to your computer and use it in GitHub Desktop.
Save MiaofeiWang/c3f3d9227809f2a29f4f5fcb6711f0ef to your computer and use it in GitHub Desktop.
Shared with Script Lab
name: Shape - New shape and connector
description: ''
author: MiaofeiWang
host: EXCEL
api_set: {}
script:
content: |
$("#run").click(() => tryCatch(run));
async function run() {
await Excel.run(async (context) => {
let sheet = context.workbook.worksheets.getActiveWorksheet();
let shapes = sheet.shapes;
let shape = shapes.addGeometricShape("IrregularSeal1", 50, 50, 100, 100);
//let newconnector = shapes.addConnector("CurvedConnector5", 150, 150, 20, 50);
await context.sync();
let count = shapes.getCount();
shape.load(["width", "height"]);
await context.sync();
console.log("Succeed to add shape! Width: " + shape.width + ", Height: " + shape.height);
console.log("Shape count: " + count.value);
});
}
/** 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
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