Last active
November 6, 2021 02:45
-
-
Save ErickPetru/8de1661fab34fe93d874e19b47df1d54 to your computer and use it in GitHub Desktop.
This file contains hidden or 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: Lista de Exercícios 2 - Item 1 | |
description: '' | |
host: EXCEL | |
api_set: {} | |
script: | |
content: "const field1 = document.getElementById(\"name\") as HTMLInputElement;\r\nconst field2 = document.getElementById(\"type\") as HTMLSelectElement;\r\nconst field3 = document.getElementById(\"breed\") as HTMLInputElement;\r\nconst field4 = document.getElementById(\"weight\") as HTMLInputElement;\r\nconst save = document.getElementById(\"save\") as HTMLButtonElement;\r\nconst show = document.getElementById(\"show\") as HTMLButtonElement;\r\n\r\nconst pets = [];\r\n\r\nsave.addEventListener(\"click\", () => {\r\n Excel.run(async (context) => {\r\n const sheet = context.workbook.worksheets.getActiveWorksheet();\r\n sheet.getUsedRange().clear();\r\n\r\n if (!field1.value || !field2.value || !field3.value || !field4.value) {\r\n sheet.getRange(\"A1\").values = [[\"Todos os campos são obrigatórios!\"]];\r\n sheet.getUsedRange().format.autofitColumns();\r\n return;\r\n }\r\n\r\n const pet = {\r\n name: field1.value,\r\n type: field2.value,\r\n breed: field3.value,\r\n weight: field4.valueAsNumber\r\n };\r\n\r\n pets.push(pet);\r\n\r\n field1.value = \"\";\r\n field2.value = \"\";\r\n field3.value = \"\";\r\n field4.value = \"\";\r\n });\r\n});\r\n\r\nshow.addEventListener(\"click\", () => {\r\n Excel.run(async (context) => {\r\n const sheet = context.workbook.worksheets.getActiveWorksheet();\r\n sheet.getUsedRange().clear();\r\n\r\n for (let i = 1; i <= pets.length; i++) {\r\n const pet = pets[i - 1];\r\n sheet.getRange(`A${i}:D${i}`).values = [[pet.name, pet.type, pet.breed, pet.weight]];\r\n }\r\n\r\n sheet.getRange(\"D1:D999\").numberFormat = [[\"0.0\"]];\r\n sheet.getUsedRange().format.autofitColumns();\r\n });\r\n});\r\n" | |
language: typescript | |
template: | |
content: "<h1>Cadastro de Pets</h1>\r\n\r\n<div>\r\n\t<input id=\"name\" placeholder=\"Nome\">\r\n\t<select id=\"type\">\r\n\t\t<option value=\"\">Tipo</option>\r\n\t\t<option>Cachorro</option>\r\n\t\t<option>Gato</option>\r\n\t</select>\r\n\t<input id=\"breed\" placeholder=\"Raça\">\r\n\t<input id=\"weight\" type=\"number\" placeholder=\"Peso\">\r\n</div>\r\n\r\n<br>\r\n\r\n<div>\r\n\t<button id=\"save\">Salvar</button>\r\n\t<button id=\"show\">Exibir na Planilha</button>\r\n</div>" | |
language: html | |
style: | |
content: '' | |
language: css | |
libraries: |- | |
https://appsforoffice.microsoft.com/lib/1/hosted/office.js | |
@types/office-js | |
[email protected]/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