您有2個選項。首先是使用Google表格中的標準query()函數來獲取值。這裏的缺點是它只是價值的參考。所以,你不能對它們重新排序等。爲了利用這一點,把這個單元格A1,它會拉頭和檢索從A列中的值和C:
=QUERY(A:C, "select A, C where B = 'blue'", 1)
對於谷歌Apps腳本答案: 這將遍歷您的清單表,每一行,其中列B是藍色將保存在列A和列A和新的工作表和B的值C:
function doIt(){
var activeSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet4");
var lastRow = activeSheet.getLastRow();
var lastCol = activeSheet.getLastColumn();
var targetValues = [];
var sourceSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("List");
var lastSourceRow = sourceSheet.getLastRow();
var lastSourceCol = sourceSheet.getLastColumn();
var sourceRange = sourceSheet.getRange(1, 1, lastSourceRow, lastSourceCol);
var sourceData = sourceRange.getValues();
var activeRow = 0;
//Loop through every retrieved row from the Source
for (row in sourceData) {
//IF Column B in this row has 'blue', then work on it.
if (sourceData[row][1] === 'blue') {
//Save it ta a temporary variable
var tempvalue = [sourceData[row][0], sourceData[row][2]];
//then push that into the variables which holds all the new values to be returned
targetValues.push(tempvalue);
}
}
//Save the new range to the appropriate sheet starting at the last empty row
activeSheet.getRange(lastRow + 1, 1 , targetValues.length, 2).setValues(targetValues);
}
當然,你可以通過通過替換2行來測試函數的值。第一,限定功能:
function doIt(testingvar){
傳遞變量稱爲testingvar,和測試線替換與傳遞的變量硬編碼的測試:
if (sourceData[row][1] === testingvar) {