我正在尝试解析一个谷歌电子表格,它在合并的单元格中保存评论。
我正在尝试从范围中提取和创建“移位”对象:
/**
* Return shifts object
* @contextSheet the sheet that is being parsed
* @baseTime the relative time that represent day 1
*/
extractShiftsFromSpreadSheet : function (contextSheet,baseTime) {
var shifts = [];
var ss = contextSheet;
//For each day of the week:
for(var dayIndex = 1; dayIndex <7 ; dayIndex++) {
var day = Script.Util.getDayByNum(dayIndex-1); //Convert day num to day string
var ShiftRangePerDay = Script.SpreadSheet.getShiftRangeByDay(ss,day);
var notes = ShiftRangePerDay.getComments();
var rows = ShiftRangePerDay.getNumRows();
var cols = ShiftRangePerDay.getNumColumns();
var values = ShiftRangePerDay.getValues();
var startTime;
var endTime;
var note = '';
for (i = 0; i <= rows - 1; i++) {
for (j = 0; j <= cols - 1; j++) {
//var cell = values[i][j];
var studentName = values[i][j].trim();
//if the cell value isn't a student, move on to the next cell
if(!Script.Util.isValidStudent(studentName)) continue;
// otherwise, it is a valid student shift: create it!
try {
note = notes[i][j];
}
catch(err) {
//skip
}
if(note !== '' && typeof note !== 'undefined') {
Logger.log("note found for "+studentName+"." +" note:"+ note);
}
现在,var notes = ShiftRangePerDay.getComments(); 根据以下 API 参考,行应该返回一个 String[][] 对象,我应该能够从中读取: https ://developers.google.com/apps-script/reference/spreadsheet/range?hl=en #getComments()
但是,它不起作用。我尝试过使用 getComments()、getNotes() 甚至 getCell(i,j).getNote()。这里似乎没有任何工作。
看来我在这里错过了一些东西,我很想听听你的想法。