Last active
July 31, 2019 16:22
-
-
Save lemkorp/b52645a914818963d3d44fb5a6f9e736 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: tableau 1 | |
description: Create a new snippet from a blank template. | |
host: EXCEL | |
api_set: {} | |
script: | |
content: | | |
$("#creation").click(() => tryCatch(creation)); | |
$("#ajout").click(() => tryCatch(ajoutDonnees)); | |
$("#somme").click(() => tryCatch(somme)); | |
async function creation() { | |
await Excel.run(async function(context) { | |
let feuille = context.workbook.worksheets.getActiveWorksheet(); | |
// Création du tableau avec en-tête | |
let t = feuille.tables.add("A1:C1", true); | |
t.name = "ventes"; // Nom du tableau | |
t.getHeaderRowRange().values = [["Formation", "Nombre", "Prix"]]; // En-têtes | |
// Ajout de lignes à la fin du tableau ou index | |
t.rows.add(null, [ | |
["Office 2016", 2, 1200], | |
["Office 2019", 3, 1400], | |
["Office 2016", 1, 1200], | |
["Windows 10", 1, 950], | |
["Office 2019", 3, 1400], | |
["Windows 10", 9, 950], | |
["Office 2019", 2, 1400] | |
]); | |
}); | |
} | |
async function ajoutDonnees() { | |
await Excel.run(async function(context) { | |
let feuille = context.workbook.worksheets.getActiveWorksheet(); | |
let t = feuille.tables.getItem("ventes"); | |
let nouveau = [["Office 2019", 13, 1400]]; | |
t.rows.add(null, nouveau); | |
t.columns.add(null, [ | |
["Total"], | |
["=[Nombre]*[Prix]"], | |
["=[Nombre]*[Prix]"], | |
["=[Nombre]*[Prix]"], | |
["=[Nombre]*[Prix]"], | |
["=[Nombre]*[Prix]"], | |
["=[Nombre]*[Prix]"], | |
["=[Nombre]*[Prix]"], | |
["=[Nombre]*[Prix]"] | |
]); | |
}); | |
} | |
async function somme() { | |
await Excel.run(async function(context) { | |
let feuille = context.workbook.worksheets.getActiveWorksheet(); | |
let t = feuille.tables.getItem("ventes"); | |
let nouveau = [["", "=SUM(B2:B9)", "=AVERAGE(C2:C9)", "=SUM(D2:D9)"]]; | |
t.rows.add(null, nouveau); | |
}); | |
} | |
/** 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="creation" class="ms-Button"> | |
<span class="ms-Button-label">Création du tableau</span> | |
</button> | |
<button id="ajout" class="ms-Button"> | |
<span class="ms-Button-label">Ajout de données</span> | |
</button> | |
<button id="somme" class="ms-Button"> | |
<span class="ms-Button-label">Somme, moyenne et total</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.3.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment