我的电子表格中有一栏如下
function cabList(cabID, column1) {
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Input1');
var data = ss.getDataRange().getValues();
var length = data.length,
count1 = 0,
count2 = 0,
outputArray = [],
shiftData = [],
temp = [];
var shift = ss.getRange(3, 11, ss.getLastRow(), 1).getValues();
for (i = 0; i < length; i++) {
var tt = shift[i].split(" ");
shiftData[i] = tt[0];
if (data[i][column1] === cabID && shiftData[i] === 'Login') {
count1 += 1;
} else if (data[i][column1] === cabID && shiftData[i] === 'Logout') {
count2 += 1;
}
}
temp[0] = cabID;
temp[1] = count1;
temp[2] = count2;
outputArray.push(temp);
}
我想分割(登录/退出和时间),我想将前半部分(即登录/退出)存储在一个数组中
{{1}}
我正在尝试此代码,但我收到一个名为
的错误TypeError:无法在对象Login 11:30找到功能拆分
答案 0 :(得分:0)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var finalarray = {};
for(var i=1; i<=sheet.getRange("a1:a6").getValues().length; i++){
var testcol = sheet.getRange("a"+i).getValue();
var tt=testcol.split(" ");
finalarray[i-1] = tt[0];
}
Logger.log(finalarray);
=============================================== =====
function cabList(cabID, column1) {
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Input1');
var data = ss.getDataRange().getValues();
var length = data.length,
count1 = 0,
count2 = 0,
outputArray = [],
shiftData = [],
temp = [];
for(var i = 3; i<=ss.getLastRow(); i++){
for(var j = 11; j>=1; j--){
var shift = sheet.getRange(i, j, i, 1).getValue();
var tt = shift.split(" ");
shiftData[k] = tt[0];
k++;
if (data[i][column1] === cabID && shiftData[i] === 'Login') {
count1 += 1;
} else if (data[i][column1] === cabID && shiftData[i] === 'Logout') {
count2 += 1;
}
}
}
temp[0] = cabID;
temp[1] = count1;
temp[2] = count2;
outputArray.push(temp);
}
希望这会对你有所帮助。
感谢。