我有一个 Google 电子表格,使用此github 链接中给出的脚本从融合表中添加数据。我在电子表格的右端添加了两列,其中一列使用公式填充
=COUNTIF(A$2:A$24,A2)
和其他列由另一个公式。目前,每次使用新行更新电子表格时,我都会手动拖动公式列来更新其中的数据。是否可以使用脚本动态更新公式列?即,当行添加公式列也动态更新。
编辑:
// evaluate project type and set identifier
function addCountIfFormulaToCell(){
// add the id of your spreadsheet here
var sss = SpreadsheetApp.openById('0AozvCNI02VmpdG5tb0pkUGdDR3djMm5NV0pYeThFbGc');
// add the name of the sheet here
var ss = sss.getSheetByName('Sheet1');
// column you want to evaluate for the formula
var columnToEvaluateAgainst = "A";
// column you want to add the formula to
var columnToAddFormulaTo = "H";
// identifies the last row
var lastRow = ss.getLastRow();
// is the cell to evaluate in the last row
var evaluateThisCell = columnToEvaluateAgainst + lastRow;
// is the cell that gets the forumla in the last row
var addFormulaToThisCell = columnToAddFormulaTo + lastRow;
// this is my formula
var projectFormula = "COUNTIF(A$2:$A,A2)";
// grabs the cell that gets the forumla in the last row
var ssCellToGetFormula = ss.getRange(addFormulaToThisCell);
// sets the formula to the cell in the last row
ssCellToGetFormula.setFormula(projectFormula);
};