V
V
Vladimir Zuev2020-06-05 06:23:25
Google Sheets
Vladimir Zuev, 2020-06-05 06:23:25

What is the best way to upload a list of cities received from Nova Poshta to a Google spreadsheet?

Hello.
What is the best way to upload a list of cities received from Nova Poshta to a Google spreadsheet? This list contains 4550 items.
In the answer that comes from Nova Poshta, the list is divided into 100 items. It is better to unload in one column or in 46 columns. By default, there are only 1000 lines per page. Who has already worked with this list. Tell me how best to unload for further work with this list? And at the same time, the code that can be used to upload this list. Thanks in advance to everyone who helps.
Program code for getting a list of cities from Nova Poshta

function getCities () {
  const formData = {
    // Ваш ключ API 2.0
    "apiKey": '********************************************',
    
    "modelName": "Address",
    
    "calledMethod": "getCities"
  };
  
  const options = {
    "method": "POST",
    "headers": {
      "Content-Type": "application/json"
    },
    "payload": JSON.stringify(formData)
  };
  
  const url = "https://api.novaposhta.ua/v2.0/json/";
  
  const response = UrlFetchApp.fetch(url, options);
  
  var orderList =  JSON.parse(response.getContentText());
  var orderList = JSON.stringify(orderList, null, 2);
  //Logger.log(orderList);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ivanov, 2020-06-05
@oshliaer

There are 5M cells in the Table. Upload as you like.
Main idea:

  1. Get cities
  2. As long as there are cities paste down tables
  3. Get cities
  4. Back to 2

How to Insert Down Tables
/**
 *
 * @param {GoogleAppsScript.Spreadsheet.Sheet} sheet
 * @param {Array.<Array.<string>>} data
 * @return {GoogleAppsScript.Spreadsheet.Range}
 */
function appendData(sheet, data) {
  const lastRow = sheet.getLastRow() + 1;
  return sheet
    .getRange(lastRow, 1, lastRow + data.length, data[0].length)
    .setValues(data);
}

Note that you must supply a two-dimensional array.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question