So I have this code about getting a distance using Google API and JavaScript to an Excel file:[enter image description here][1]
Office.onReady((info) => {
if (info.host === Office.HostType.Excel) {
document.getElementById("sideload-msg").style.display = "none";
document.getElementById("app-body").style.display = "flex";
document.getElementById("run").onclick = run;
}
});
// Get directionsData.distance.text from taskpane.html
var jarak = localStorage.getItem("distanceValue");
// "Type in excel" code
export async function run() {
try {
await Excel.run(async (context) => {
/**
* Insert your Excel code here
*/
const range = context.workbook.getSelectedRange();
// Read the range address
range.load("address");
// Fill in the value
range.values = jarak;
await context.sync();
console.log(`The range address was ${range.address}.`);
});
} catch (error) {
console.error(error);
}
}
What I’d like to ask is if I change the range.values = jarak;
to range.values = [[jarak], [latitude], [longitude]];
(The additional parameters will be defined later).
I want the code to let me only select one cell from excel and it fills the next 2 cells (using the new range.values
I defined here will add it to the next column). The problem is that I have to select the 3 cells in order to let the excel fills the new range.values
which is an array if I recall the name correctly.
How can I let the range.values
fills in as an array even if I only select one cell in excel?
The excel interface I made is like this: https://i.stack.imgur.com/Nh3YG.png