Last active
July 14, 2018 09:38
-
-
Save maninweb/0aa612a00c0beb153b10538c7472dc5a to your computer and use it in GitHub Desktop.
Format a range - Geteilt mit Script Lab.
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: Formating Dates Sample | |
description: Format a range | |
author: maninweb | |
host: EXCEL | |
api_set: {} | |
script: | |
content: | | |
$("#setup").click(setup); | |
$("#set-date-format").click(setDateFormat); | |
async function setDateFormat() { | |
try { | |
await Excel.run(async (context) => { | |
const sheet = context.workbook.worksheets.getItem("Sample"); | |
const formats = [ | |
["DD.MM.YYYY"], | |
["YYYY-MM-DD"], | |
["MM/DD/YYYY"] | |
]; | |
const range = sheet.getRange("A2:A4"); | |
range.numberFormat = formats; | |
await context.sync(); | |
}); | |
} | |
catch (error) { | |
OfficeHelpers.UI.notify(error); | |
OfficeHelpers.Utilities.log(error); | |
} | |
} | |
async function setup() { | |
try { | |
await Excel.run(async (context) => { | |
const sheet = await OfficeHelpers.ExcelUtilities | |
.forceCreateSheet(context.workbook, "Sample"); | |
const data = [ | |
['Date', 'Dummy'], | |
[43295, 'This is date 1'], | |
[43295, 'This is date 1'], | |
[43295, 'This is date 1'] | |
]; | |
const range = sheet.getRange("A1:B4"); | |
range.values = data; | |
range.format.autofitColumns(); | |
sheet.activate(); | |
await context.sync(); | |
}); | |
} | |
catch (error) { | |
OfficeHelpers.UI.notify(error); | |
OfficeHelpers.Utilities.log(error); | |
} | |
} | |
language: typescript | |
template: | |
content: "<section class=\"ms-font-m\">\n <p>This sample shows how to format a range using the Excel API.</p>\n</section>\n\n<section class=\"setup ms-font-m\">\n <h3>Set up</h3>\n <button id=\"setup\" class=\"ms-Button\">\n <span class=\"ms-Button-label\">Add sample data</span>\n </button>\n</section>\n\n<section class=\"samples ms-font-m\">\n <h3>Try it out</h3>\n\t<button id=\"set-date-format\" class=\"ms-Button\">\n <span class=\"ms-Button-label\">Set date format</span>\n </button>\n</section>\n" | |
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: | | |
# Office.js | |
https://appsforoffice.microsoft.com/lib/1/hosted/office.js | |
# CSS Libraries | |
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 | |
# NPM libraries | |
core-js@2.4.1/client/core.min.js | |
@microsoft/office-js-helpers@0.7.4/dist/office.helpers.min.js | |
jquery@3.1.1 | |
# IntelliSense: @types/library or node_modules paths or URL to d.ts files | |
@types/office-js | |
@types/core-js | |
@microsoft/office-js-helpers@0.7.4/dist/office.helpers.d.ts | |
@types/jquery |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment