Google Apps脚本电子表格注释自动化 [英] Google Apps Script Spreadsheet Comment Automation

查看:470
本文介绍了Google Apps脚本电子表格注释自动化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我有一个关于Google Apps指令码的问题,特别是针对试算表。我已查看此处的文档(是,在表中的文档一个电子表格),但我还没有能够找到我要找的。以下是站点:



1。)当在Google电子表格中编辑单元格时,我使用功能(SET)是的,它说的是 cell.setComment(),但实际上它创建了一个注释,感谢您的一致性,Google!):

  function onEdit(){
var doc = SpreadsheetApp.getActiveSpreadsheet();
var sheet = doc.getActiveSheet();
var cell = sheet.getActiveCell();
cell.setComment(Last revised:+(new Date()));
}

2。)注意事项已于2012年9月5日被注释取代


对于两种类型的单元格记法,只有 SET 注释/注释,而不是 ADD



4。)我想引用或编写一个能够添加新注释/注释的函数(最好是注释,它们更容易阅读),而不是设置注释/注释。



5。)您可以通过GUI在电子表格中手动添加注释/注释(右键单击单元格并选择插入注释或插入注释因为这些右键单击功能存在导致我相信我们可以编写一个脚本来做同样的事情,但在单元格被编辑时自动地称为脚本。



6。)此函数将用于跟踪单元修订历史记录。我知道我可以创建一个新的电子表格,并将修订历史记录轻松地发送到新的电子表格,但考虑到我有10个电子表格需要跟踪,我宁愿没有10个新的电子表格来跟踪历史。



如果任何人可以帮助我,那将非常感谢!

解决方案

无法通过电子表格服务操纵评论 - 请参阅 Issue 2566



相反,所有的评论方法都适用于Notes。



以下方法将为任何现有的时间戳添加一个新的修改的时间戳 - 不太好看,因为实际的注释将是不幸的。

  function onEdit(){
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var cell = sheet.getActiveCell();
var comment = cell.getComment();
//换行符在msgBox中工作,但不在注释中。
comments = comments +\\\\
Modified:+(new Date());
//Browser.msgBox(comments);
cell.setComment(comments);
}


Today I have a question about Google Apps Scripts, specifically for Spreadsheets. I've already looked at the documentation here (yes, documentation on a Sheet within a Spreadsheet), but I haven't been able to find what I'm looking for. Here's the sitch:

1.) When a cell is edited in a Google Spreadsheet, the function I have SETS a NOTE using the function (yes it says cell.setComment(), but in reality it creates a Note. Thanks for being consistent, Google!):

function onEdit() {
var doc = SpreadsheetApp.getActiveSpreadsheet();
var sheet = doc.getActiveSheet();
var cell = sheet.getActiveCell();
cell.setComment("Last modified: + (new Date()));
}

2.) Notes have been 'replaced' by Comments as of... September 5th, 2012? Maybe? I would rather use those instead.

3.) For both types of 'cell notation', there exist functions only to SET the Note/Comment, and not ADD (according to the documentation).

4.) I would like to reference or write a function that has the capability to ADD a new Note/Comment (preferably Comment, they are more easily read), instead of setting the Note/Comment.

5.) You can MANUALLY add a Note/Comment through the GUI in the Spreadsheet itself (right-click a cell and select "Insert Note" or "Insert comment". Because these right-click functions exist leads me to believe that we could write a script to do the same thing, but have it be called auto-magically when the cell has been edited.

6.) This function will be used to keep track of cell revision history. I know that I can create a new spreadsheet and send the revision history to that new spreadsheet easily, but considering that I have 10 spreadsheets that need to be tracked, I would rather not have 10 new spreadsheets to keep track of history. Keeping it in the same spreadsheet will keep things simple.

If anyone could help me out, it would be greatly appreciated!

解决方案

There is no way to manipulate Comments via Spreadsheet Services - see Issue 2566. (Star it if you wish.)

Instead, all the "Comments" methods work on Notes.

The following method will append a new "Modified" timestamp to any existing one - not quite as nice looking as an actual Comment would be, unfortunately.

function onEdit() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet();
  var cell = sheet.getActiveCell();
  var comments = cell.getComment();
  // Newline works in msgBox, but not in Note.
  comments = comments + "\\nModified: " + (new Date());
  //Browser.msgBox(comments);
  cell.setComment(comments);
}

这篇关于Google Apps脚本电子表格注释自动化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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