获取单元格中注释的最后一行或第一行并将其添加 [英] get last row or first row of a note in a cell and add to it

查看:77
本文介绍了获取单元格中注释的最后一行或第一行并将其添加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

听起来超级简单,但我无法弄清楚.我有一个脚本,用于更新内置在单元格中的注释.问题是我希望它以注释为基础.因此,获取便笺的最后一行还是获取第一行,对我来说如何格式化都无关紧要.问题在于它覆盖了先前的注释.

Sounds super simple but I can't figure it out. I have a script that updates a note that is built into a cell. The problem is I want it to build upon the note. So either get last row of the note or get first row, doesn't matter to me how It is formatted. The problem is it writes over the previous note.

function Note() {
  var spreadsheet = SpreadsheetApp.getActive();
  var timezone = Utilities.formatDate(new Date(), "GMT-4", "M/dd/yy', 'h:mm a"); // Get the current time;
  spreadsheet.getActiveRange().setNote('Notes:\n\n-updated file on ' + timezone + '\n\n' + '-');
};

理想情况下,我希望将此注释放在注释的顶部,而不要覆盖注释的任何其他部分.这样,如果您愿意,它只是运行中的便笺或日志.我要将其添加到我正在运行的许多其他功能中,以便每次在该文件上运行一个功能时都有一个日志.

Ideally I would like it to put this note at the top of the note and not write over any other part of the note. This way it is just a running note or log if you will. I am going to add this to many other functions I have running so I have a log of every time a function was run on that file.

推荐答案

这对我有用.只需检查便笺是否存在,如果存在,便会重写便笺,但要添加新文本.

This worked for me. Just check if the note exists, and if it does, rewrites the note but before it adds the new text.

function Note() {
  var spreadsheet = SpreadsheetApp.getActive();
  var ss = spreadsheet.getSheets()[0];
  var timezone = Utilities.formatDate(new Date(), "GMT-4", "M/dd/yy', 'h:mm a"); // Get the current time;
  var range = ss.getActiveRange();
  var note = range.getNote();

  if (note) {
    note = note + '\n\n-updated file on ' + timezone + '\n\n';
    range.setNote(note);

  }else {
    range.setNote('Notes:\n\n-updated file on ' + timezone + '\n\n'); 
    }

}

这篇关于获取单元格中注释的最后一行或第一行并将其添加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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