Google apps script 如何使用其他电子表格中的应用程序脚本跟踪一个电子表格中的数据更改?
我可能遇到了相当大的挑战: 跟踪数据更改并在主电子表格中记录“注释”,并在其他电子表格中记录应用程序脚本 我有一个包含数据集的行。 对于主工作表中的每个数据行,存在另一个“历史记录”-电子表格(例如)。这些“历史记录”表应(1)跟踪数据更改,(2)记录相应行的“注释”Google apps script 如何使用其他电子表格中的应用程序脚本跟踪一个电子表格中的数据更改?,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我可能遇到了相当大的挑战: 跟踪数据更改并在主电子表格中记录“注释”,并在其他电子表格中记录应用程序脚本 我有一个包含数据集的行。 对于主工作表中的每个数据行,存在另一个“历史记录”-电子表格(例如)。这些“历史记录”表应(1)跟踪数据更改,(2)记录相应行的“注释” 例如 (1) 如果有人更改了应用程序脚本中第2行中的值,则应在相应的电子表格(在本例中)第2行和第3行之间插入一行(始终在这两行之间),并添加第4、6或7行中的信息 (2) 如果有人在F列的某一行中输入“注释”,应用程序脚本应再
例如 (1) 如果有人更改了应用程序脚本中第2行中的值,则应在相应的电子表格(在本例中)第2行和第3行之间插入一行(始终在这两行之间),并添加第4、6或7行中的信息 (2) 如果有人在F列的某一行中输入“注释”,应用程序脚本应再次在相应的电子表格第2行和第3行之间插入一行,并添加注释,如中的第3行或第5行。最后,删除数据电子表格中的注释
我搜索了很多,但没有找到任何有用的东西。 不幸的是,我不是一个程序员。 任何帮助都将不胜感激 致以最良好的祝愿,
Alex我在应用程序脚本中使用onEdit()事件执行类似的操作。您可以将其更改为在附加到其他工作表之前添加用户的注释
function appendLine() {
var sessionEmail = Session.getActiveUser().getEmail().toString();
var spreadsheetTimeZone = SpreadsheetApp.getActive().getSpreadsheetTimeZone();
var lastUpdatedString = Utilities.formatDate(new Date(), spreadsheetTimeZone, "MM/dd/yyyy' 'HH:mm:ss");
var s = SpreadsheetApp.getActiveSheet();
if (s.getName() == "Workload") { //checks that we're on the correct sheet
var r = s.getActiveCell();
if (r.getColumn() == 14) { //checks the column
var status = r.getValue();
var note = r.offset(0, -1);
var noteValue = note.getValue()
var delivery = r.offset(0, -5);
var deliveryValue = delivery.getValue().toString();
}
// Validating fields are filled in
if (status == "Complete") {
var ui = SpreadsheetApp.getUi();
if (noteValue == '') { // if no note is entered, stop script with message box
var noStatus = ui.alert(
'Warning!',
'Please enter notation before choosing Complete.',
ui.ButtonSet.OK);
r.setValue('')
return;
}
// get array values
var array = [lastUpdatedString, sessionEmail, deliveryValue, noteValue]
// insert at row 2 of destination, so newest note is always at the top and found in the index(match())
var ss = SpreadsheetApp.getActiveSpreadsheet();
var pasteSheet = ss.getSheetByName("Historical Notes Sheet");
var lock = LockService.getScriptLock();
lock.waitLock(30000);
try {
var index = 2;
pasteSheet.insertRowBefore(index).getRange(index, 1, 1, array.length).setValues([array]);
SpreadsheetApp.flush();
} finally {
lock.releaseLock();
}
// clear response row
note.setValue('')
r.setValue('')
}
}
}
1.很简单:选项A:在接收电子表格中作为webapp发布,并转发原始电子表格中安装了onEdit
触发器的函数捕获的onEdit
事件对象。您需要以自己的身份运行webapp,并允许匿名访问。可能最好通过范围检查来关闭对UrlFetch
的调用。选项B:为对源电子表格进行更改的任何人提供对“跟踪器工作簿”的编辑访问权限,并使源电子表格的OneEdit触发功能远程打开另一个工作簿(通过SpreadsheetApp.openById),添加必要的信息。