OPen an empty spreadsheet
Go to plugins
Goto macros
paste in macro
change your two currencies
I used CLP and USD
and CLF (UF) and USD
set to run on sheet open
Site REST call docs are here https://exchangerate.host/
=================================================
const oWorksheet = Api.GetActiveSheet();
oWorksheet.GetRange(“A1:A1”).SetValue(“CLP to USD:”);
oWorksheet.GetRange(“A1:A1”).AutoFit(false, true);
oWorksheet.GetRange(“A2:A2”).SetValue(“UF to USD:”);
const d = new Date();
const xhr = new XMLHttpRequest();
var xhrURL = ‘https://api.exchangerate.host/convert?from=CLP&to=USD’;
xhr.open(“GET”, xhrURL, true);
xhr.onload = (e) => {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
//console.log(xhr.responseText);
var response = xhr.responseText;
var array = response.split(’,’);
var rate = array[7].split(’:’);
var rateis = Number(rate[2].replace(/[^0-9.]/, ‘’));
console.log(rateis);
oWorksheet.GetRangeByNumber(0, 1).SetValue(rateis);
oWorksheet.GetRangeByNumber(0, 2).SetValue(d);
} else {
console.error(xhr.statusText);
}
}
};
xhr.onerror = (e) => {
console.error(xhr.statusText);
};
xhr.send(null);
const xhr2 = new XMLHttpRequest();
var xhrURL2 = ‘https://api.exchangerate.host/convert?from=CLF&to=USD’;
xhr2.open(“GET”, xhrURL2, true);
xhr2.onload = (e) => {
if (xhr2.readyState === 4) {
if (xhr2.status === 200) {
//console.log(xhr.responseText);
var response2 = xhr2.responseText;
var array2 = response2.split(’,’);
var rate2 = array2[7].split(’:’);
var rateis2 = Number(rate2[2].replace(/[^0-9.]/, ‘’));
console.log(rateis2);
oWorksheet.GetRangeByNumber(1, 1).SetValue(rateis2);
} else {
console.error(xhr2.statusText);
}
}
};
xhr2.onerror = (e) => {
console.error(xhr2.statusText);
};
xhr2.send(null);