Created
May 28, 2017 16:41
-
-
Save Tomamais/8a498137408f1b31f9a5a576d3003f74 to your computer and use it in GitHub Desktop.
Shared with 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: Teste Script Lab - Coletando CEPs | |
description: '' | |
author: Tomamais | |
host: EXCEL | |
api_set: {} | |
script: | |
content: | | |
$("#run").click(run); | |
async function getAddressByCEP(CEP: string) { | |
$.ajax({ | |
url: `https://correiosapi.apphb.com/cep/${CEP}`, | |
dataType: 'jsonp', | |
crossDomain: true, | |
contentType: "application/json", | |
statusCode: { | |
200: function(data) { return data; } // Ok | |
,400: function(msg) { console.log(msg); } // Bad Request | |
,404: function(msg) { console.log("CEP não encontrado!!"); } // Not Found | |
} | |
}); | |
} | |
async function run() { | |
try { | |
await Excel.run(async (context) => { | |
const wsCEPs = context.workbook.worksheets.getItem("CEPs"); | |
const usedRange = wsCEPs.getUsedRange(); | |
usedRange.load(); | |
await context.sync(); | |
console.log(usedRange.address); | |
console.log(usedRange.values); | |
for (const value of usedRange.values) { | |
const CEP = value[1]; | |
console.log(CEP); | |
console.log(await getAddressByCEP(CEP)); | |
//console.log(value[1]); | |
//const cell = usedRange.getCell(value[1], 1); | |
// console.log(cell); | |
} | |
}); | |
} | |
catch (error) { | |
OfficeHelpers.UI.notify(error); | |
OfficeHelpers.Utilities.log(error); | |
} | |
} | |
language: typescript | |
template: | |
content: | | |
<button id="run" class="ms-Button"> | |
<span class="ms-Button-label">Run</span> | |
</button> | |
language: html | |
style: | |
content: "/* Your style goes here */\r\n" | |
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.1/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.1/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