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: EX 03
description: Create a new snippet from a blank template.
host: EXCEL
api_set: {}
script:
content: "const run = document.getElementById(\"run\");\r\nrun.addEventListener(\"click\", async () => {\r\n await Excel.run(async (context) => {\r\n const folha1 = context.workbook.worksheets.getActiveWorksheet();\r\n let folha2 = context.workbook.worksheets.getItemOrNullObject(\"Inverter\");\r\n let folha3 = context.workbook.worksheets.getItemOrNullObject(\"Alfabetico\");\r\n if (folha2 || folha3) folha2.delete(), folha3.delete();\r\n folha2 = context.workbook.worksheets.add(\"Inverter\");\r\n folha3 = context.workbook.worksheets.add(\"Alfabetico\");\r\n\r\n const range1 = folha1.getRange(\"A1\").getExtendedRange(\"Down\");\r\n range1.load([\"Values\", \"rowCount\"]);\r\n await context.sync();\r\n\r\n const range2 = folha2.getRange(`A1:A${range1.rowCount}`);\r\n const range3 = folha3.getRange(`A1:A${range1.rowCount}`);\r\n range3.values = range1.values;\r\n range2.values = range1.values;\r\n\r\n range2.values.reverse();\r\n const table1 = folha2.tables.add(range2, false);\r\n table1.getHeaderRowRange().values = [[\"Pessoas\"]];\r\n const body1 = table1.getDataBodyRange();\r\n body1.format.autofitColumns();\r\n\r\n const table2 = folha3.tables.add(range3, false);\r\n table1.getHeaderRowRange().values = [[\"Pessoas\"]];\r\n const body2 = table2.getDataBodyRange();\r\n body2.sort.apply([{ key: 0, ascending: true }]);\r\n body2.format.autofitColumns();\r\n\r\n await context.sync();\r\n });\r\n});\r\n"
language: typescript
template:
content: "<div class=\"buttons\">\r\n\t<button id=\"run\">RUN</button>\r\n</div>"
language: html
style:
content: ''
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment