How to Autofill last row with formula, when data is received from IFTTT on the last row?

前端 未结 2 560
庸人自扰
庸人自扰 2021-01-17 08:02

I have a spreadsheet: https://docs.google.com/spreadsheets/d/1df2cp4DsJvSeBvhsNjLgIa5x_RO1X7s_APRdFzU6jqQ/edit?usp=sharing

|    | C                                    


        
2条回答
  •  伪装坚强ぢ
    2021-01-17 09:00

    Solution:

    • This solution uses google-apps-script. This does not need array formulas, but uses autofill. For the solution to work, you should not use array formula, but plain formula.
    • Get the active range, which will represent the current range inserted onChange or onFormSubmit.
    • offset the range to the right to get the calculated columns and expand the range to all of calculated columns on the right.
    • Use range.autoFillToNeighbor to fill all the calculated regions of the range.

    Sample script:

    /**
     * @param {GoogleAppsScript.Events.SheetsOnChange|GoogleAppsScript.Events.SheetsOnFormSubmit} e
     */
    const onFormSubmitORonChange = e => {
      const rg = SpreadsheetApp.getActiveRange(),
        wd = rg.getWidth(),
        sh = rg.getSheet(),
        lc = sh.getLastColumn(),
        numRows = Math.max(
          rg
            .offset(0, wd, 1, 1)
            .getNextDataCell(SpreadsheetApp.Direction.UP)
            .getRow() - 1,
          1
        ),
        numCols = lc - wd;
      sh.getRange(2, wd + 1, numRows, numCols).autoFillToNeighbor(
        SpreadsheetApp.AutoFillSeries.DEFAULT_SERIES
      );
    };
    

    References:

    • How to create a onFormSubmit or onChange trigger for this function?

提交回复
热议问题