Last active
August 1, 2019 09:04
-
-
Save lemkorp/6ff83fc6b63acaf8adc40671ad8fd154 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: feuilles | |
description: Create a new snippet from a blank template. | |
host: EXCEL | |
api_set: {} | |
script: | |
content: | | |
$("#ajouter").click(() => tryCatch(ajouter)); | |
$("#copier").click(() => tryCatch(copier)); | |
$("#supprimer").click(() => tryCatch(supprimer)); | |
$("#visibilite").click(() => tryCatch(changerVisibilite)); | |
$("#grille").click(() => tryCatch(grilleOnOff)); | |
$("#entete").click(() => tryCatch(enteteOnOff)); | |
$("#calcul").click(() => tryCatch(desactiverCalcul)); | |
$("#figer").click(() => tryCatch(figer)); | |
async function ajouter() { | |
await Excel.run(async function(context) { | |
let feuille2 = context.workbook.worksheets.add(); | |
feuille2.name = "nouveau"; | |
}); | |
} | |
async function copier() { | |
await Excel.run(async function(context) { | |
let feuille1 = context.workbook.worksheets.getItem("Feuil1"); | |
feuille1.copy(Excel.WorksheetPositionType.after, feuille1); | |
let feuille2 = context.workbook.worksheets.getActiveWorksheet(); | |
feuille2.name = "copie"; | |
}); | |
} | |
async function supprimer() { | |
await Excel.run(async function(context) { | |
let copie = context.workbook.worksheets.getItem("copie"); | |
copie.delete(); | |
}); | |
} | |
async function changerVisibilite() { | |
await Excel.run(async function(context) { | |
let copie = context.workbook.worksheets.getItem("copie"); | |
copie.load("visibility"); | |
await context.sync(); | |
if (copie.visibility == "Visible") copie.visibility = "Hidden"; | |
else copie.visibility = "Visible"; | |
}); | |
} | |
async function grilleOnOff() { | |
await Excel.run(async function(context) { | |
let copie = context.workbook.worksheets.getItem("copie"); | |
copie.load("showGridlines"); | |
await context.sync(); | |
copie.showGridlines = !copie.showGridlines; | |
}); | |
} | |
async function enteteOnOff() { | |
await Excel.run(async function(context) { | |
let copie = context.workbook.worksheets.getItem("copie"); | |
copie.load("showHeadings"); | |
await context.sync(); | |
copie.showHeadings = !copie.showHeadings; | |
}); | |
} | |
async function desactiverCalcul() { | |
await Excel.run(async function(context) { | |
let copie = context.workbook.worksheets.getItem("copie"); | |
copie.load("enableCalculation"); | |
await context.sync(); | |
if (copie.enableCalculation) $("#calcul span").html("Activer les calculs"); | |
else $("#calcul span").html("Désactiver les calculs"); | |
copie.enableCalculation = !copie.enableCalculation; | |
}); | |
} | |
async function figer() { | |
await Excel.run(async function(context) { | |
let copie = context.workbook.worksheets.getItem("copie"); | |
let panes = copie.freezePanes; | |
const frozen = panes.getLocationOrNullObject(); | |
await context.sync(); | |
console.log(frozen); | |
if (frozen.isNullObject) { | |
panes.freezeRows(1); | |
panes.freezeColumns(1); | |
} else panes.unfreeze(); | |
}); | |
} | |
/** 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="ajouter" class="ms-Button"> | |
<span class="ms-Button-label">Ajouter la feuille nouveau au classeur</span> | |
</button> | |
<button id="copier" class="ms-Button"> | |
<span class="ms-Button-label">Copier Feuil1 dans la feuille copie</span> | |
</button> | |
<button id="supprimer" class="ms-Button"> | |
<span class="ms-Button-label">Supprimer la feuille copie</span> | |
</button> | |
<button id="visibilite" class="ms-Button"> | |
<span class="ms-Button-label">Visibilité de la feuille copie</span> | |
</button> | |
<button id="grille" class="ms-Button"> | |
<span class="ms-Button-label">Visibilité de la grille dans la feuille copie</span> | |
</button> | |
<button id="entete" class="ms-Button"> | |
<span class="ms-Button-label">Afficher/cacher les en-têtes de la feuille copie</span> | |
</button> | |
<button id="calcul" class="ms-Button"> | |
<span class="ms-Button-label">Désactiver les calculs</span> | |
</button> | |
<button id="figer" class="ms-Button"> | |
<span class="ms-Button-label">Figer / libérer 1 ligne et 1 colonne</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