0
我有一個數據集,並在此選擇行是鏈接爲:從谷歌電子表格中某一列的值不爲空,使用谷歌Apps腳本
https://docs.google.com/spreadsheets/d/1QgR7WC2bj2_AW7yTDnjEXDrYKGo1GR_w_ea-8PtRwm4/edit?usp=sharing
所以,我要的是,如果列A中的任何單元格有一個日期(非空),我想要獲取整個行。
我甚至得到了在堆棧溢出一個腳本是:
function copynotempty(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh = SpreadsheetApp.setActiveSheet(ss.getSheets()[0])
var col = 0 ; // choose the column you want to check: 0 = col A, 1= col B ...
var range = sh.getDataRange();
var values=range.getValues();// data is a 2D array, index0 = col A
var formulas=range.getFormulas();// data is a 2D array, index0 = col A
var target=new Array();// this is a new array to collect data
for(n=0;n<range.getHeight();++n){
if (values[n][col]!=''){ ;
for (cc=0;cc<range.getWidth();++cc){
if (values[n][cc]!=''){target[n][cc]=values[n][cc]}
// if the cell has a formula copy it or else copy the value, do that for the whole row
// (this also defines and apply the 'priority' you mentioned in your question, I wasn't sure if it should apply to the whole row or only on column B)
}
}
}
if(target.length>0){// if there is something to copy
var sh2=SpreadsheetApp.setActiveSheet(ss.getSheets()[1]); //second sheet of your spreadsheet
sh2.getRange(1,1,target.length,target[0].length).setValues();// paste the selected values in the 2cond sheet
}
}
但如果我用這個,我共享我得到這個錯誤「類型錯誤:無法設置屬性‘數據集0.0’的未定義到「被邀請」(第12行,「代碼」文件)「。
在此先感謝。
非常感謝這個腳本。但是,例如,如果我有sheet1中的數據集,並且如果我嘗試通過在sheet2中寫入「= copynotempty(Sheet1!A:E)」來使用腳本,它是空的,它將拋出一個錯誤「您沒有權限調用setNumberFormat第4行)「。你有什麼想法爲什麼會發生這種情況? –
更新了示例腳本。它將結果導入到sheet2。 – Tanaike
也謝謝你。你可以按接受按鈕來解決你的這個問題嗎? – Tanaike