Skip to content

Instantly share code, notes, and snippets.

@DominguesM
Created November 18, 2021 17:21
Show Gist options
  • Save DominguesM/3ba7d6d2e69d93c379d3e6ab835f85e0 to your computer and use it in GitHub Desktop.
Save DominguesM/3ba7d6d2e69d93c379d3e6ab835f85e0 to your computer and use it in GitHub Desktop.
3. Um suplemento com botão que deve percorrer valores em uma lista de nomes de pessoas previamente preenchidos pelo usuário na coluna A, na folha de trabalho ativa da planilha Excel aberta, considerando-se que a quantidade de linhas com nomes preenchidos é incerta. Por fim, deve-se exibir na coluna B os nomes na ordem inversa ao qual foram digit…
name: Revisão - 3
description: >-
3. Um suplemento com botão que deve percorrer valores em uma lista de nomes de
pessoas previamente preenchidos pelo usuário na coluna A, na folha de trabalho
ativa da planilha Excel aberta, considerando-se que a quantidade de linhas com
nomes preenchidos é incerta. Por fim, deve-se exibir na coluna B os nomes na
ordem inversa ao qual foram digitados.
host: EXCEL
api_set: {}
script:
content: |
$("#run").click(() => tryCatch(run));
async function run() {
await Excel.run(async (context) => {
let lista_nomes = [];
// mudar a constante size para englobar mais linhas
// deixei com poucas para ficar mais facil o desenvolvimento
const SIZE = 11;
const sheet = context.workbook.worksheets.getActiveWorksheet();
let range = sheet.getRange(`A1:A${SIZE}`);
range.load("values");
await context.sync();
// PEGA TODOS OS NOMES DIGITADOS
for (let i = 0; i < SIZE; i++) {
let row = range.values[i];
if (row[0] == ""){
// CASO ENCONTRE UMA LINHA VAZIA ENCERRA O LOOP
break;
};
lista_nomes.push(row[0]);
};
lista_nomes = lista_nomes.reverse();
for (let i = 0; i < SIZE; i++) {
console.log(i);
let cel = sheet.getRange(`B${i + 1}`);
cel.values = [[lista_nomes[i]]];
};
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: |
<button id="run" class="ms-Button">
<span class="ms-Button-label">Run</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
[email protected]/dist/css/fabric.min.css
[email protected]/dist/css/fabric.components.min.css
[email protected]/client/core.min.js
@types/core-js
[email protected]
@types/[email protected]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment