Importing data with formula from another google sheet and deleting original data

前端 未结 1 924
予麋鹿
予麋鹿 2020-12-02 03:09

I am using the following script to import data from another Google Sheet but it doesn´t bring in the formula I need with it.

I have tried ImportRange but

相关标签:
1条回答
  • 2020-12-02 03:52

    Issue:

    • Formulas are not retrieved with getValues()

    Possible Solutions:

    • Use range#getFormulas and range#getValues and mix those two arrays to create a array of formulas and values to setValues() later.
    • Use Advanced Google Services to access Sheets API to directly get the mix.

    Sample Script Snippets:

      var data = range.getValues();
      data = range.getFormulas().map(function(e, i) {//i=index of row(e)
        return e.map(function(f, j) {//j = index of column(f)
          return f === "" ? data[i][j] : f;
        });
      });
    

    or

      var req = {
        ranges: 'results!2:688',
        valueRenderOption: 'FORMULA', //get formulas with values
      };
      var r = Sheets.Spreadsheets.Values.batchGet('Sheet 1 ID', req);
      data = r.valueRanges[0].values;
    

    References:

    • getFormulas
    • EnablingAdvancedServices
    • batchGet
    0 讨论(0)
提交回复
热议问题