Created
May 17, 2024 01:22
-
-
Save Celscius/b5c3aa4ee75a0ce5d7f1e8578a9ee37f to your computer and use it in GitHub Desktop.
import single array to googlesheet
This file contains hidden or 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
| //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