简体   繁体   English

如何将此脚本更改为不删除而是替换为空单元格

[英]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()实现它。

From : 来自:

sh.deleteRows(2, range.getNumRows() - 1);

To : 至 :

sh.getRange(2, 1, range.getNumRows() - 1, sh.getLastColumn()).clear();

Reference : 参考:

If I misunderstand your question, I'm sorry. 如果我误解了您的问题,对不起。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用应用程序脚本删除特定列中的空单元格? - How to delete the empty cells in a specific column using apps script? 如何使用应用脚本删除特定的单元格? - How to delete specific cells with app script? 谷歌应用脚本搜索和替换删除多个文档中的空行 - Google app script search and replace delete empty line in several documents 如何使用谷歌脚本在一行中查找未定义或空的单元格? - How to find undefined or empty cells in a row with google script? 如何让 Google 脚本忽略空单元格? - How do I make Google script ignore empty cells? 如何有一个工作的谷歌表脚本,只在空单元格上运行,让其他单元格完好无损 - How to have a working google sheets script, that only runs on empty cells leaving other cells intact 如何用“字符串”替换Google表格列中非空单元格的值? - How to replace values of non-empty cells in a Google Sheets Column with a “String”? 从 Google 表格插入数据库时,如何用 null 替换空单元格值 - How can I replace empty cells value with null when inserting into database from Google Sheets 查找和替换包含特定值的单元格的脚本 - Script to Find & Replace cells that CONTAIN a certain value Google Script自动隐藏空白单元格,应该刷新吗? - Google Script to autohide empty cells, should refresh?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM