Created
January 24, 2024 19:58
-
-
Save mcpsmith/6dfc93a9d1fc070121b958d4fb619168 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: Blank snippet | |
description: Create a new snippet from a blank template. | |
host: EXCEL | |
api_set: {} | |
script: | |
content: | | |
$("#run").click(() => tryCatch(run)); | |
async function run() { | |
await Excel.run(async (context) => { | |
const sheet = context.workbook.worksheets.getActiveWorksheet(); | |
console.log("Running sample"); | |
let range = sheet.getRange("A1:E5"); | |
let formula1 = "=A1+B1"; | |
await context.sync(); | |
const rows = []; | |
const formats = []; | |
const headerProps = { | |
// Any subproperties of format that are not set will not be changed when these cell properties are set. | |
format: { | |
font: { | |
bold: true | |
} | |
} | |
}; | |
const indentProps = { | |
// Any subproperties of format that are not set will not be changed when these cell properties are set. | |
format: { | |
indentLevel: 2 | |
} | |
}; | |
for (let i = 0; i < 5; i++) { | |
rows[i] = ["1", "2", "X", "X",formula1]; | |
if(i%2==0) { | |
formats[i] = [{}, {}, {}, {}, headerProps]; | |
} | |
else { | |
formats[i] = [{}, {}, {}, {}, indentProps]; | |
} | |
} | |
range.values = rows; | |
await context.sync(); | |
range.setCellProperties(formats); | |
// You can use empty JSON objects to avoid changing a cell's properties. | |
// range.setCellProperties([ | |
// [topHeaderProps, {}, {}, {}, {}], | |
// [{}, {}, headerProps, headerProps, headerProps], | |
// [{}, headerProps, nonApplicableProps, matchupScoreProps, matchupScoreProps], | |
// [{}, headerProps, matchupScoreProps, nonApplicableProps, matchupScoreProps], | |
// [{}, headerProps, matchupScoreProps, matchupScoreProps, nonApplicableProps] | |
// ]); | |
await context.sync(); | |
console.log("Running Complete"); | |
}); | |
} | |
/** Default helper for invoking an action and handling errors. */ | |
async function tryCatch(callback) { | |
try { | |
await callback(); | |
} catch (error) { | |
// Note: In a production add-in, you'd want to notify the user through your add-in's UI. | |
console.error(error); | |
} | |
} | |
language: typescript | |
template: | |
content: | | |
<button id="run" class="ms-Button"> | |
<span class="ms-Button-label">Run</span> | |
</button> | |
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/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 | |
jquery@3.1.1 | |
@types/jquery@3.1.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment