我有以下脚本(1年前实施的第1个脚本)将行表单1张移动到另一张表格(在google工作表/工作簿中)。问题是不会带有评论。有谁知道如何在从工作表到工作表的过渡中包含任何未解决的注释?
var objSettings = {
sheets : ['CHECK', 'STAGE2', 'READY', 'SCHEDULED', 'ARCHIVE', 'WASTE'],
shActive : [1, 1, 1, 1, 1, 1],
column : 1,} function onEdit(e) {try{var sh = e.range.getSheet();if (e.range.getNumRows() == 1 && e.range.getNumColumns() == 1 && e.range.getColumn() == objSettings.column) {
var sheetName = '';
for (var i = 0; i < objSettings.sheets.length; i++) {
if (objSettings.sheets[i] == sh.getName().trim().toUpperCase()) {
if (objSettings.shActive[i] == 1) {
Logger.log(('' + e.value).trim().toUpperCase() );
Logger.log(sh.getName().trim().toUpperCase());
if (('' + e.value).trim().toUpperCase() != sh.getName().trim().toUpperCase()) {
var shDest = e.source.getSheetByName(e.value);
if (!(shDest)) {
var shDest = e.source.getSheetByName(('' + e.value).trim().toProperCase());
}
if (!(shDest)) {
var shDest = e.source.getSheetByName(('' + e.value).trim().toLowerCase());
}
if (!(shDest)) {
var shDest = e.source.getSheetByName(('' + e.value).trim().toUpperCase());
}
Logger.log(shDest);
if (shDest) {
var currRow = e.range.getRow();
var dataDest = shDest.getDataRange().getValues();
for (var j = 3; j < dataDest.length; j++) {
if (('' + dataDest[j][objSettings.column - 1]).length == 0) {
break;
}
}
var lastRow = j;
for (var k = 0; k < objSettings.sheets.length; k++) {
if (('' + e.value).trim().toUpperCase() == objSettings.sheets[k]) {
var type = objSettings.shActive[k];
break;
}
}
var dataR = sh.getRange(currRow, 1, 1, sh.getLastColumn()).getValues();
if (type == 1) {
shDest.getRange(lastRow + 1, 1, 1, dataR[0].length).setValues(dataR);
} else {
var dataR0 = dataR[0];
dataR0.shift();
shDest.getRange(lastRow + 1, 1, 1, dataR[0].length).setValues([dataR0]);
}
sh.deleteRow(currRow);
Logger.log(currRow);
Logger.log(lastRow + 1);
Logger.log(type);
sh.getParent().toast('The row has been moved!', 'Info');
}
}
}
break;
}
}
}}catch(e){
SpreadsheetApp.getUi().alert(e); } }
或者,如果您认为有更好的更稳定的方法来实现这一点,请告诉我。
答案 0 :(得分:0)
使用moveTo()剪切并粘贴带注释的范围。
Comments是Drive API的一部分。
Enable Advanced Drive Service使用Drive.Comments.{}
然后,您可以查看status
"open" || "resolved"
属性
function moveComments () {
var ss = SpreadsheetApp.getActive();
var range_one = ss.getSheets()[0].getRange("A10");
var range_two = ss.getSheets()[1].getRange("A10");
// Get a list of all comments in the workbook
var workbook_comments = Drive.Comments.list(ss.getId());
/*
var comment_cell_value = workbook_comments.items[0].context.value;
var check_status = workbook_comments.items[0].status; // "open" || "resolved"
*/
// Move the range with comments to another sheet.range
range_one.moveTo(range_two);
}