[英]How to change this script to not to delete but replace with empty cells
So I have this Script: 所以我有这个脚本:
function Copy() {
var sh = SpreadsheetApp.getActive().getSheetByName('Form Responses')
var range = sh.getDataRange().offset(1, 0);
var data = range.getValues();
var ts = SpreadsheetApp.openById('x').getSheetByName('backup')
ts.getRange(ts.getLastRow() + 1, 1, data.length, data[0].length).setValues(data);
sh.deleteRows(2, range.getNumRows() - 1);
}
How should I change it to not delete that that line but replace it with empty cells? 我应该如何更改它以不删除该行,而是将其替换为空单元格? Because I'm referring to those cells in another sheet and every time after the script runs those references got to #referror. 因为我是在另一张工作表中引用这些单元格,并且每次脚本运行后,这些引用都指向#referror。 And I'm guessing its because of the deleting. 我猜是因为删除。
I understood that you want to clear cell values but you don't want to delete rows by sh.deleteRows(2, range.getNumRows() - 1);
我知道您想清除单元格值,但不想通过sh.deleteRows(2, range.getNumRows() - 1);
删除行sh.deleteRows(2, range.getNumRows() - 1);
. 。 If my understanding is correct, how about this modification? 如果我的理解是正确的,那么该修改如何? You can achieve it using clear()
. 您可以使用clear()
实现它。
sh.deleteRows(2, range.getNumRows() - 1);
sh.getRange(2, 1, range.getNumRows() - 1, sh.getLastColumn()).clear();
If I misunderstand your question, I'm sorry. 如果我误解了您的问题,对不起。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.