Skip to content

Instantly share code, notes, and snippets.

@Celscius
Created May 17, 2024 01:22
Show Gist options
  • Save Celscius/b5c3aa4ee75a0ce5d7f1e8578a9ee37f to your computer and use it in GitHub Desktop.
Save Celscius/b5c3aa4ee75a0ce5d7f1e8578a9ee37f to your computer and use it in GitHub Desktop.
import single array to googlesheet
//create custom menu to import array
function onOpen() {
SpreadsheetApp
.getUi()
.createMenu("Custom Menu")
.addItem("import json", "displayPrompt")
.addToUi();
}
//open prompt and insert your url
function displayPrompt() {
var ui = SpreadsheetApp.getUi();
var result = ui.prompt("Please enter your url");
//Get the button that the user pressed.
var button = result.getSelectedButton();
if (button === ui.Button.OK) {
Logger.log("The user clicked the [OK] button.");
single_array_to_sheet(result.getResponseText())
} else if (button === ui.Button.CLOSE) {
Logger.log("The user clicked the [X] button and closed the prompt dialog.");
}
}
//import your array into googlesheet
single_array_to_sheet = (url) => {
try {
const sheet = "app"
const response = UrlFetchApp.fetch(url);
const data = JSON.parse(response.getContentText());
//Logger.log(data.request.reportType);
//console.log(data)
//const row = array
var app = SpreadsheetApp.getActive().getSheetByName(sheet)
app.appendRow(data);
} catch (f) {
Logger.log(f.message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment