Last active
July 30, 2018 05:05
-
-
Save MiaofeiWang/a5c9588b6c0ad082ace6354784d106fe 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: Shape - Font | |
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 count = shapes.getCount(); | |
shapes.load("items"); | |
await context.sync(); | |
let shape; | |
if (count.value > 0) | |
{ | |
shape = shapes.items[0]; | |
} | |
else | |
{ | |
shape = shapes.addGeometricShape("Rectangle", 100, 100, 100, 100); | |
await context.sync(); | |
} | |
let range = shape.textFrame.textRange; | |
range.text = "ABCDE"; | |
await context.sync(); | |
let subRange = range.getCharacters(0, 1); | |
//subRange.text = "bullet"; | |
let font = subRange.font; | |
//font.name = "Andalus"; | |
//font.bold = true; | |
//font.size = 18; | |
//font.color = "red"; | |
//font.italic = true; | |
count = shapes.getCount(); | |
range.load(); | |
subRange.load(); | |
font.load(); | |
await context.sync(); | |
console.log(`There are ${count.value} shapes.`); | |
console.log(`Range Text: ${subRange.text}`); | |
console.log(`Name: ${font.name}, Size: ${font.size}, Color: ${font.color}, Bold: ${font.bold}, Italic: ${font.italic}`); | |
}); | |
} | |
/** 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