-
-
Save vishwesh17/f1a4e24d1e2156fee6f7d51f6d00e769 to your computer and use it in GitHub Desktop.
working so far and need to play around
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: '123' | |
description: working so far and need to play around | |
host: EXCEL | |
api_set: {} | |
script: | |
content: |- | |
/** | |
* Calculates the volume of a sphere. | |
* @customfunction | |
* @param {number} radius | |
* @returns The volume of the sphere. | |
*/ | |
// JSON to CSV Converter | |
function ConvertToCSV(objArray) { | |
var sheet = context.workbook.worksheets.getItem('sample'); | |
var expensesTable = sheet.tables.add("A1:O1", true /*hasHeaders*/); | |
expensesTable.name = "ExpensesTable"; | |
expensesTable.getHeaderRowRange().values = [["id", "name", "symbol", "rank", "price_usd", "price_btc", "24h_volume_usd", "market_cap_usd", "available_supply", "total_supply", "max_supply", "percent_change_1h", "percent_change_24h", "percent_change_7d", "last_updated" ]]; | |
if (Office.context.requirements.isSetSupported("ExcelApi", "1.2")) { | |
sheet.getUsedRange().format.autofitColumns(); | |
sheet.getUsedRange().format.autofitRows(); | |
var array = typeof objArray != "object" ? JSON.parse(objArray) : objArray; | |
var str = "["; | |
for (var i = 0; i < array.length; i++) { | |
var line = "["; | |
for (var index in array[i]) { | |
if (line != "[") line += ","; | |
line += array[i][index]; | |
} | |
line+="]," | |
str += line + "\r\n"; | |
} | |
str+= "]"; | |
expensesTable.rows.add(str) | |
return str; | |
return | |
} | |
function trial() { | |
var obj; | |
console.log("inside trial()"); | |
return fetch("https://api.coinmarketcap.com/v1/ticker/") | |
.then((response) => response.json()) | |
.then((json) => { | |
obj.slice(5); | |
json.name; | |
console.log("inide json then.." + json.name); | |
}) | |
.then(() => obj.slice); | |
} | |
/** @customfunction */ | |
function working() { | |
var obj; | |
console.log("inside trial()"); | |
return fetch("https://api.coinmarketcap.com/v1/ticker/") | |
.then((response) => response.json()) | |
.then((json) => { | |
console.log("inide json then.." + json[0].name); | |
obj = json[0].name; | |
}) | |
.then(() => obj); | |
} | |
/** @customfunction | |
async function abc() { | |
console.log("inside trial1()"); | |
let obj = await fetch("https://api.coinmarketcap.com/v1/ticker/") | |
.then((json) => { | |
console.log("inside json then.." + json[0].name); | |
obj = json[0].name; | |
}) | |
.then(() => obj); | |
console.log("outside fetch then..." + obj); | |
return obj; | |
} | |
*/ | |
/** @customfunction */ | |
function def() { | |
var obj; | |
console.log("inside def()"); | |
return fetch("https://raw.githubusercontent.com/dariusk/corpora/master/data/animals/birds_antarctica.json") | |
.then((response) => response.json()) | |
.then((json) => { | |
console.log("inide json then.." + json[1].birds.members); | |
obj = json[1].birds.members; | |
}) | |
.then(() => obj); | |
} | |
/**@customfunction */ | |
function trialworking() { | |
var jsonObject; | |
var csv; | |
console.log("inside trialworking()"); | |
return fetch("https://api.coinmarketcap.com/v1/ticker/") | |
.then((response) => response.json()) | |
.then((json) => { | |
// Convert Object to JSON | |
jsonObject = JSON.stringify(json); | |
console.log("CSV file---" + ConvertToCSV(json)) | |
}) | |
.then(() => jsonObject); | |
} | |
/**@customfunction */ | |
function webRequest1() { | |
var jsonObject; | |
console.log("inside webRequest()"); | |
fetch("https://api.coinmarketcap.com/v1/ticker/") | |
.then((response) => response.json()) | |
.then((json) => { | |
jsonObject = JSON.stringify(json); | |
console.log("json stringify... " + jsonObject); | |
// Display JSON | |
}) | |
.then(() => { | |
console.log("inside obj then... " + jsonObject); | |
}); | |
console.log("outside fetch then... " + jsonObject); | |
return jsonObject; | |
} | |
/**@customfunction | |
function birds() { | |
var jsonObject; | |
console.log("inside birds()"); | |
return fetch("https://raw.githubusercontent.com/dariusk/corpora/master/data/animals/birds_antarctica.json") | |
.then((response) => response.json()) | |
.then((json) => { | |
// Convert Object to JSON | |
jsonObject = JSON.stringify(json); | |
var jsonobject = json.parse(json.strinify); | |
for(var i = 0; i < jsonobject; i++) | |
alert(jsonobject[i]['family']); | |
console.log("json stringify... " + jsonObject); | |
}) | |
.then(() => jsonObject); | |
} | |
language: typescript | |
libraries: | | |
https://appsforoffice.microsoft.com/lib/1/hosted/office.js | |
@types/office-js | |
core-js@2.4.1/client/core.min.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment