Merge 将两个脚本合并到一个Google工作表中
我从不同的帖子中得到了这两个脚本,我在合并它们时遇到了困难 如果状态列在Sheet1中发生更改,则短脚本会插入时间戳,而另一个脚本会创建一个更改日志,记录所做的更改。是否可以将这两个合并为一个,或者编辑变更日志,以便在编辑状态列时仅记录 提前谢谢 谷歌电子表格: 时间戳脚本:Merge 将两个脚本合并到一个Google工作表中,merge,google-sheets,timestamp,changelog,Merge,Google Sheets,Timestamp,Changelog,我从不同的帖子中得到了这两个脚本,我在合并它们时遇到了困难 如果状态列在Sheet1中发生更改,则短脚本会插入时间戳,而另一个脚本会创建一个更改日志,记录所做的更改。是否可以将这两个合并为一个,或者编辑变更日志,以便在编辑状态列时仅记录 提前谢谢 谷歌电子表格: 时间戳脚本: `function onEdit(e) { var sheet = e.source.getActiveSheet(); if (sheet.getName() == "Sheet1") { var r =
`function onEdit(e) {
var sheet = e.source.getActiveSheet();
if (sheet.getName() == "Sheet1") {
var r = e.source.getActiveRange();
if (r.getColumn() == 3) {
sheet.getRange(r.getRow(),r.getColumn()+1).setValue(new Date());
}
}
}
`
更改日志脚本:
function onEdit() {
// This script records changes to the spreadsheet on a "Changelog" sheet.
// The changelog includes these columns:
// "Timestamp", "Sheet name", "Cell address", "Column label", "Row label", "Value entered"
// Version 1.1, written by --Hyde, 30 July 2014
// See https://productforums.google.com/d/topic/docs/7CaJ_nYfLnM/discussion
// edit the following lines to suit your needs
// changes are only recorded from sheets listed below
// escape regular expression metacharacters as in \. \$ \+ \* \? \( \) \[ \]
// see http://en.wikipedia.org/wiki/Regular_expression
// use '.+' to include all sheets
var sheetsToWatch = ['outcome overview', 'Sheet1', 'Another sheet'];
// name of the sheet where the changelog is stored
var changelogSheetName = "Changelog";
var timestamp = new Date();
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var cell = sheet.getActiveCell();
var sheetName = sheet.getName();
// if it is the changelog sheet that is being edited, do not record the change
if (sheetName == changelogSheetName) return;
// if the sheet name does not appear in sheetsToWatch, do not record the change
var matchFound = false;
for (var i = 0; i < sheetsToWatch.length; i++) {
if (sheetName.match(sheetsToWatch[i])) matchFound = true;
}
if (!matchFound) return;
var columnLabel = sheet.getRange(/* row 1 */ 1, cell.getColumn()).getValue();
var rowLabel = sheet.getRange(cell.getRow(), /* column A */ 1).getValue();
var changelogSheet = ss.getSheetByName(changelogSheetName);
if (!changelogSheet) {
// no changelog sheet found, create it as the last sheet in the spreadsheet
changelogSheet = ss.insertSheet(changelogSheetName, ss.getNumSheets());
// Utilities.sleep(2000); // give time for the new sheet to render before going back
// ss.setActiveSheet(sheet);
changelogSheet.appendRow(["Timestamp", "Sheet name", "Cell address", "Column label", "Row label", "Value entered"]);
changelogSheet.setFrozenRows(1);
}
changelogSheet.appendRow([timestamp, sheetName, cell.getA1Notation(), columnLabel, rowLabel, cell.getValue()]);
}
函数onEdit(){
//此脚本将电子表格的更改记录在“更改日志”表中。
//变更日志包括以下列:
//“时间戳”、“工作表名称”、“单元格地址”、“列标签”、“行标签”、“输入值”
//版本1.1,作者——海德,2014年7月30日
//看https://productforums.google.com/d/topic/docs/7CaJ_nYfLnM/discussion
//编辑以下行以满足您的需要
//更改仅记录在下面列出的表格中
//转义正则表达式元字符,如\.\$\+\*\?\(\)\[\]
//看http://en.wikipedia.org/wiki/Regular_expression
//使用“.+”包含所有图纸
var sheetsToWatch=[‘结果概述’、‘Sheet1’、‘另一张表’];
//存储更改日志的工作表的名称
var changelogSheetName=“Changelog”;
var timestamp=新日期();
var ss=SpreadsheetApp.getActiveSpreadsheet();
var sheet=ss.getActiveSheet();
var cell=sheet.getActiveCell();
var sheetName=sheet.getName();
//如果正在编辑的是变更记录表,则不要记录变更
如果(sheetName==changelogSheetName)返回;
//如果图纸名称未出现在sheetsToWatch中,请勿记录更改
var matchFound=false;
对于(变量i=0;i
尝试重命名函数并仅添加一个onEdit
:
function onEdit(e) {
myFunction1(e); // call function #1
myFunction2(); // call function #2
}
尝试重命名函数并仅添加一个
onEdit
:
function onEdit(e) {
myFunction1(e); // call function #1
myFunction2(); // call function #2
}