M
M
Max2017-11-22 11:02:41
Google Sheets
Max, 2017-11-22 11:02:41

How to organize the collection of price changes in a Google spreadsheet?

I take data (prices) from the site into Google spreadsheets through the importxml formula.
Prices change periodically.
How to organize the collection of price changes on the machine, and so that the old prices remain?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ivanov, 2017-11-23
@jjsf

You can use Google Apps Script
Easiest way
Run a time based trigger on a functionmyF

function myF(){
  var data = get_();
  Logger.log(data);
  append_(data);
}

function get_(){
  var sheet = SpreadsheetApp.openById("986327f36403948feb4a")
    .getSheetByName("Sheet1");
  return sheet.getDataRange().getValues().slice(sheet.getFrozenRows());
}

function append_(data){
  var d = new Date();
  var values = data.map(function(row){
    row.unshift(this.d);
    return row;
  }, {d:d});
  var sheet = SpreadsheetApp.openById("579e832d1ced2a2cc76c")
    .getSheetByName("Sheet2");
  sheet.getRange(sheet.getLastRow() + 1, 1, values.length, values[0].length).setValues(values);
}

The right way
You need to implement a function that will receive data from the site, convert it to a table dataand add it to the Table append_(data). Add this function to the time based trigger.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question