Skip to content

Instantly share code, notes, and snippets.

@lemkorp
Last active August 2, 2019 14:36
Show Gist options
  • Save lemkorp/0725f2f3da894bb6394a1b550f3bb831 to your computer and use it in GitHub Desktop.
Save lemkorp/0725f2f3da894bb6394a1b550f3bb831 to your computer and use it in GitHub Desktop.
Create a new snippet from a blank template.
name: Mise en forme conditionnelle
description: Create a new snippet from a blank template.
host: EXCEL
api_set: {}
script:
content: |
$("#rouge").click(() => tryCatch(negatifEnRouge));
$("#effacer").click(() => tryCatch(effacerLesRegles));
$("#echelle").click(() => tryCatch(echelle));
$("#databar").click(() => tryCatch(dataBar));
$("#icones").click(() => tryCatch(icones));
$("#supprdoublons").click(() => tryCatch(supprimerDoublons));
async function negatifEnRouge() {
await Excel.run(async (context) => {
const plage = context.workbook.worksheets.getActiveWorksheet().getRange("B2:C5");
const condFormat = plage.conditionalFormats.add(Excel.ConditionalFormatType.cellValue);
condFormat.cellValue.rule = { formula1: "=0", operator: "LessThan" };
condFormat.cellValue.format.font.color = "red";
});
}
async function effacerLesRegles() {
await Excel.run(async (context) => {
const plage = context.workbook.worksheets.getActiveWorksheet().getRange("B2:C5");
const condFormat = plage.conditionalFormats.clearAll();
});
}
async function echelle() {
await Excel.run(async (context) => {
const plage = context.workbook.worksheets.getActiveWorksheet().getRange("B2:C5");
const condFormat = plage.conditionalFormats.add(Excel.ConditionalFormatType.colorScale);
const critere = {
minimum: {
formula: null,
type: Excel.ConditionalFormatColorCriterionType.lowestValue,
color: "green"
},
midpoint: {
formula: 50,
type: Excel.ConditionalFormatColorCriterionType.percent,
color: "yellow"
},
maximum: {
formula: null,
type: Excel.ConditionalFormatColorCriterionType.highestValue,
color: "red"
}
};
condFormat.colorScale.criteria = critere;
});
}
async function dataBar() {
await Excel.run(async (context) => {
const plage = context.workbook.worksheets.getActiveWorksheet().getRange("B2:C5");
const condFormat = plage.conditionalFormats.add(Excel.ConditionalFormatType.dataBar);
});
}
async function icones() {
await Excel.run(async (context) => {
const plage = context.workbook.worksheets.getActiveWorksheet().getRange("B2:C5");
const condFormat = plage.conditionalFormats.add(Excel.ConditionalFormatType.iconSet);
condFormat.iconSet.style = Excel.IconSet.threeTriangles;
});
}
async function supprimerDoublons() {
await Excel.run(async (context) => {
const plage = context.workbook.worksheets.getActiveWorksheet().getRange("A1:C5");
plage.removeDuplicates([0], true);
//deleteResult.load();
});
}
/** 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="rouge" class="ms-Button">
<span class="ms-Button-label">Négatif en rouge</span>
</button>
<button id="effacer" class="ms-Button">
<span class="ms-Button-label">Effacer les règles</span>
</button>
<button id="echelle" class="ms-Button">
<span class="ms-Button-label">Echelle de couleurs</span>
</button>
<button id="databar" class="ms-Button">
<span class="ms-Button-label">Data bar</span>
</button>
<button id="icones" class="ms-Button">
<span class="ms-Button-label">Icones</span>
</button>
<button id="supprdoublons" class="ms-Button">
<span class="ms-Button-label">Supprimer les doublons</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