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

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

问题描述

今天我有一个关于 Google Apps 脚本的问题,专门针对电子表格.我已经查看了此处的文档(是的,Sheet 中的文档电子表格),但我一直无法找到我要找的东西.关键是:

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.) 当在 Google 电子表格中编辑单元格时,我使用该函数设置了一个 NOTE(是的,它说 cell.setComment(),但实际上它创建了一个注释.感谢您的一致性,谷歌!):

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.) 截至 2012 年 9 月 5 日,注释已被评论替换"?或许?我宁愿使用它们.

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

3.) 对于两种类型的单元格符号",存在仅用于 SET 注释/注释的函数,而不是 ADD(根据文档).

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

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

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.) 您可以通过电子表格本身的 GUI 手动添加注释/注释(右键单击单元格并选择插入注释"或插入注释".因为这些右键单击功能的存在让我相信我们可以编写一个脚本来做同样的事情,但是当单元格被编辑时它会自动神奇地调用.

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.) 此函数将用于跟踪单元格修订历史.我知道我可以创建一个新电子表格并将修订历史轻松发送到该新电子表格,但考虑到我有 10 个需要跟踪的电子表格,我宁愿没有 10 个新电子表格来跟踪历史记录.将其保存在同一个电子表格中会使事情变得简单.

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!

推荐答案

无法通过电子表格服务操作评论 - 请参阅 问题 36756650.(如果您愿意,请给它加星标.)

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

相反,所有评论"方法都适用于 Notes.

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天全站免登陆