从Google脚本中获取注释 [英] Getting comments from range in Google Script

查看:58
本文介绍了从Google脚本中获取注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试解析一个Google电子表格,该电子表格在合并的单元格中包含注释.

I'm trying to parse a Google spreadsheet, that holds comments within merged cells.

我正在尝试从以下范围提取并创建"shift"对象:

I'm trying to extract and create 'shift' objects from the range:

/**    
* 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注释= ShiftRangePerDay.getComments();根据以下API参考,代码行应返回String [] []对象,并且我应该能够从中读取内容: https://developers.google.com/apps -script/reference/spreadsheet/range?hl = zh-CN#getComments()

now, the var notes = ShiftRangePerDay.getComments(); line should return a String[][] object and I should be able to read from it, according to the following API reference: https://developers.google.com/apps-script/reference/spreadsheet/range?hl=en#getComments()

但是,它不起作用. 我试过使用getComments(),getNotes()甚至getCell(i,j).getNote(). 这里似乎没有任何作用.

However, it does not work. I've tried using getComments() , getNotes() and even getCell(i,j).getNote(). Nothing seems to be working here.

似乎我在这里错过了一些东西,很想听听您对此的看法.

It seems that I've missed something here, and I would love to hear what you think of it.

推荐答案

处理注释的方法已损坏,如

The methods dealing with comments are broken, as reported in Issue 2566. Star it to receive updates, and to help drive up the priority of a fix.

如果您使用Notes(而非注释),则应该会发现您的代码有效.注释在Sheets用户界面中不太友好,但是至少它们(排序)与脚本一起使用.

If you use Notes (not Comments), you should find that your code works. Notes are less user-friendly in the Sheets UI, but at least they (sorta) work with scripts.

这篇关于从Google脚本中获取注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆