Last active
August 1, 2019 13:24
-
-
Save lemkorp/0b1aa79b1cfcd866d67416d1c6bedf55 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 3 | |
description: Create a new snippet from a blank template. | |
host: EXCEL | |
api_set: {} | |
script: | |
content: | | |
$("#creation").click(() => tryCatch(creation)); | |
$("#filtre").click(() => tryCatch(filtre)); | |
$("#stop").click(() => tryCatch(stopFiltre)); | |
$("#trier").click(() => tryCatch(trier)); | |
$("#seltitres").click(() => tryCatch(selTitres)); | |
$("#seldonnees").click(() => tryCatch(selDonnees)); | |
$("#seltableau").click(() => tryCatch(selTableau)); | |
$("#selcolprix").click(() => tryCatch(selColPrix)); | |
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 filtre() { | |
await Excel.run(async function(context) { | |
let feuille = context.workbook.worksheets.getActiveWorksheet(); | |
let t = feuille.tables.getItem("ventes"); | |
let filtreNombre = t.columns.getItem("Nombre").filter; | |
filtreNombre.apply({ | |
filterOn: Excel.FilterOn.values, | |
values: ["1", "2"] | |
}); | |
}); | |
} | |
async function stopFiltre() { | |
await Excel.run(async function(context) { | |
let feuille = context.workbook.worksheets.getActiveWorksheet(); | |
let t = feuille.tables.getItem("ventes"); | |
t.clearFilters(); | |
}); | |
} | |
async function trier() { | |
await Excel.run(async function(context) { | |
let feuille = context.workbook.worksheets.getActiveWorksheet(); | |
let t = feuille.tables.getItem("ventes"); | |
t.sort.apply( | |
[ | |
{ | |
key: 0, | |
ascending: true | |
} | |
], | |
true | |
); | |
}); | |
} | |
async function selTitres() { | |
await Excel.run(async function(context) { | |
let feuille = context.workbook.worksheets.getActiveWorksheet(); | |
let t = feuille.tables.getItem("ventes"); | |
t.getHeaderRowRange().select(); | |
}); | |
} | |
async function selDonnees() { | |
await Excel.run(async function(context) { | |
let feuille = context.workbook.worksheets.getActiveWorksheet(); | |
let t = feuille.tables.getItem("ventes"); | |
t.getDataBodyRange().select(); | |
await context.sync(); | |
}); | |
} | |
async function selTableau() { | |
await Excel.run(async function(context) { | |
let feuille = context.workbook.worksheets.getActiveWorksheet(); | |
let t = feuille.tables.getItem("ventes"); | |
t.getRange().select(); | |
}); | |
} | |
async function selColPrix() { | |
await Excel.run(async function (context) { | |
let feuille = context.workbook.worksheets.getActiveWorksheet(); | |
let t = feuille.tables.getItem("ventes"); | |
t.columns.getItem("Prix").getRange().select(); | |
}); | |
} | |
/** 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="filtre" class="ms-Button"> | |
<span class="ms-Button-label">Filtre sur Nombre = 1 ou 2</span> | |
</button> | |
<button id="stop" class="ms-Button"> | |
<span class="ms-Button-label">Annuler le filtre</span> | |
</button> | |
<button id="trier" class="ms-Button"> | |
<span class="ms-Button-label">Tri croissant sur la 1ère colonne</span> | |
</button> | |
<button id="seltitres" class="ms-Button"> | |
<span class="ms-Button-label">Sélectionner la ligne de titre</span> | |
</button> | |
<button id="seldonnees" class="ms-Button"> | |
<span class="ms-Button-label">Sélectionner des données</span> | |
</button> | |
<button id="seltableau" class="ms-Button"> | |
<span class="ms-Button-label">Sélectionner tout le tableau</span> | |
</button> | |
<button id="selcolprix" class="ms-Button"> | |
<span class="ms-Button-label">Sélectionner la colonne Prix</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