Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create a new snippet from a blank template.
name: Apparence
description: Create a new snippet from a blank template.
host: EXCEL
api_set: {}
script:
content: |
$("#ligne1").click(() => tryCatch(ligne1));
$("#colonnea").click(() => tryCatch(colonneA));
$("#colonnesbd").click(() => tryCatch(colonnesBD));
$("#plagec2d4").click(() => tryCatch(plageC2D4));
$("#autofitb").click(() => tryCatch(autofitB));
$("#autofit").click(() => tryCatch(autofit));
$("#fusionneretcentrer").click(() => tryCatch(fusionnerEtCentrer));
async function ligne1() {
await Excel.run(async (context) => {
const feuille1 = context.workbook.worksheets.getActiveWorksheet();
feuille1.getRange("1:1").format.font.name = "Arial";
feuille1.getRange("1:1").format.font.size = 16;
feuille1.getRange("1:1").format.font.italic = true;
feuille1.getRange("1:1").format.font.bold = true;
feuille1.getRange("1:1").format.font.color = "red";
feuille1.getRange("1:1").format.font.color = "#ff0000";
});
}
async function colonneA() {
await Excel.run(async (context) => {
const feuille1 = context.workbook.worksheets.getActiveWorksheet();
feuille1.getRange("A:A").format.horizontalAlignment = "Right";
feuille1.getRange("A:A").format.fill.color = "yellow";
});
}
async function colonnesBD() {
await Excel.run(async (context) => {
const feuille1 = context.workbook.worksheets.getActiveWorksheet();
feuille1.getRange("B:B").numberFormat = <any>"0.00";
feuille1.getRange("D:D").numberFormat = <any>"0.00";
});
}
async function plageC2D4() {
await Excel.run(async (context) => {
const feuille1 = context.workbook.worksheets.getActiveWorksheet();
feuille1.getRange("C2:D4").numberFormat = [["0.00", "0.000"], ["0.00", "0.000"], ["0.00", "0.000"]];
});
}
async function autofitB() {
await Excel.run(async (context) => {
const feuille1 = context.workbook.worksheets.getActiveWorksheet();
feuille1.getRange("B:B").format.autofitColumns();
});
}
async function autofit() {
await Excel.run(async (context) => {
const feuille1 = context.workbook.worksheets.getActiveWorksheet();
feuille1.getRange().format.autofitColumns();
});
}
async function fusionnerEtCentrer() {
await Excel.run(async (context) => {
const feuille1 = context.workbook.worksheets.getActiveWorksheet();
feuille1.getRange("E15").values = [["Paris 2024 JO d'été"]];
feuille1.getRange("E15:G15").merge();
feuille1.getRange("E15").format.horizontalAlignment = "Center";
//feuille1.getRange("E15:G15").unmerge();
});
}
/** 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="ligne1" class="ms-Button">
<span class="ms-Button-label">Ligne 1 en Arial 16 Gras Italique Rouge</span>
</button>
<button id="colonnea" class="ms-Button">
<span class="ms-Button-label">Colonne A jaune, alignée à droite</span>
</button>
<button id="colonnesbd" class="ms-Button">
<span class="ms-Button-label">Colonnes B et D 2 chiffres après virgule</span>
</button>
<button id="plagec2d4" class="ms-Button">
<span class="ms-Button-label">Format plage C2:D4</span>
</button>
<button id="autofitb" class="ms-Button">
<span class="ms-Button-label">Autofit colonne B</span>
</button>
<button id="autofit" class="ms-Button">
<span class="ms-Button-label">Autofit toutes les colonnes</span>
</button>
<button id="fusionneretcentrer" class="ms-Button">
<span class="ms-Button-label">Fusionner et centrer A15:B15</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