【发布时间】:2017-02-02 22:32:54
【问题描述】:
我有一个数据集,这里是它的链接:
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
}
}
但是如果我将它用于我共享的数据集,我会收到此错误“TypeError:无法将未定义的属性“0.0”设置为“invited”。(第 12 行,文件“代码”)”。
提前致谢。
【问题讨论】:
标签: google-apps-script google-sheets