希望有人可以帮助我,我有以下代码:
function getSSData(){
var values = SpreadsheetApp.openById('1iKO7j_ETu_x1iJf7y_ih76sDTBS21JULid_5pNIit8w').getSheets()[0].getDataRange().getValues();
var ssData = [];
// app.datasources.P11d.unload(function(){});
console.log('Made it to Line 5');
for (var i = 0; i<values.length; i++){
var newRecord = app.models.P11d.newRecord();
// add all fields to the new record
console.log('Made it to Line 9');
newRecord.MODEL_FIELD = values[i][0];
ssData.push(newRecord);
// console.log(newRecord.MODEL_FIELD);
}
console.log('Finished');
// return the array of the model.newRecord objects that would be consumed by the Model query.
return ssData;
}
我从这里的另一篇文章中得到了这个,但我似乎无法理解MODEL_FIELD部分周围发生了什么。我是否需要单独指定每个列标题,或者这只是知道该怎么做?
提前感谢您,如果问题看起来很简单,我很抱歉,我仍然非常陌生,并且在我继续前往尝试接收它。
答案 0 :(得分:1)
值是工作表中所有数据的二维数组。
实际上,代码会迭代从工作表中检索到的所有行。对于每一行,创建一个新记录,并将每行第一列中的值分配给新记录中的字段MODEL_FIELD。
每个新记录都被推送到另一个数组中,该数组返回给调用者以便用app.saveRecords()保存;