我有一個Google電子表格,使用此github link中給出的腳本將數據添加到融合表中。我添加兩列在其中一個是使用式自動拖動Google電子表格列中的公式
=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);
};
我想要類似的技術。您的公式將按照我的需要填充列。但問題是,當我使用類似'= Query(Sheet1!A1:$ G,「Select A,Count(E),G GROUP BY A,G Pivot C」)查詢來創建數據透視表時,空行也。例如,我做了一個示例[表單](https://docs.google.com/spreadsheet/ccc?key=0AozvCNI02VmpdG5tb0pkUGdDR3djMm5NV0pYeThFbGc&usp=sharing)。轉到Sheet2查詢結果。 – mpsbhat 2013-04-24 05:22:30
'= QUERY(Sheet1!A:G;「選擇A,計數(E),G其中G不是空組A,G樞軸C」) – AdamL 2013-04-24 20:27:11
它起作用..!謝謝@AdamL。 – mpsbhat 2013-04-25 04:27:27