Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sameera/40208a075eecf03553a06f396f608493 to your computer and use it in GitHub Desktop.
Save sameera/40208a075eecf03553a06f396f608493 to your computer and use it in GitHub Desktop.
Shows how to work with dates by using the Moment JavaScript library with the Moment-MSDate plug-in.
name: Working with dates
description: >-
Shows how to work with dates by using the Moment JavaScript library with the
Moment-MSDate plug-in.
host: EXCEL
api_set: {}
script:
content: |
declare var moment: any;
$("#setup").click(() => tryCatch(setup));
async function setup() {
await Excel.run(async (context) => {
context.workbook.worksheets.getItemOrNullObject("Sample").delete();
const sheet = context.workbook.worksheets.add("Sample");
const table = sheet.tables.add("A1:A6", true);
table.getHeaderRowRange().values = [["Dates"]];
table.rows.add(0, [["02/14/2020"], ["02/15/2020"], ["16/02/2020"], ["17/02/2020"], ["18/02/2020"]]);
sheet.activate();
await context.sync();
});
}
/** 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: |
<section class="ms-font-m">
<p>Demo of issue with column formating with dates</p>
</section>
<section class="setup ms-font-m">
<h3>Set up</h3>
<button id="setup" class="ms-Button">
<span class="ms-Button-label">Add sample data</span>
</button>
</section>
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
moment@2.18.1
moment-msdate@0.2.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment