如何创建一个清除电子表格中数据的按钮 [英] How to create a button which clears data in spreadsheets

查看:169
本文介绍了如何创建一个清除电子表格中数据的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我有一个谷歌电子表格文档,其中用户正在输入基于条件格式化数据的单元格正在改变颜色。我想创建一个按钮,我可以轻松地将所有单元恢复到第一个状态。



我现在有这个脚本:

  function clearRange(){
var sheet = SpreadsheetApp.getActive()。getSheetByName('Sheet1');
sheet.getRange('B13:B30')。clearContent();
}

这就像一个魅力,但事情是,我有默认数据单元格,当这些脚本被应用时,清除默认数据



任何想法如何制作这样一个脚本,它只会清除用户输入的数据。

解决方案

这不是您想要的解决方案,但除了斯科特建议的最直接的方法之外,您可以在未编辑的状态下复制表格。在这个副本中有一个脚本,它会将信息复制并粘贴到用户填写的表单中。

然后,如果您进行更改,只需更新模板而不是脚本。



这是一个非常基本的脚本,但您应该明白。

  function myFunction(){

var app = SpreadsheetApp;

var tempSheet = app.getActiveSpreadsheet()。getSheetByName('Sheet1');
var inputSheet = app.openById('----- ID of INPUT SHEET ----')。getSheetByName('Sheet1');

var tempData = tempSheet.getDataRange()。getValues();

inputSheet.getRange(1,1,tempData.length,
tempData [1] .length).setValues(tempData);
}


Currently I have a google spreadsheet document in which users are inputting data based on conditional formatting the cells are changing colors. I would like to create a button with which I can easy restore all the cells into their first state.

I have this script at the moment:

function clearRange() {
 var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');
 sheet.getRange('B13:B30').clearContent();
}

Which works like a charm but the thing is that I have default data in the cells and when this scripts get applied it clears the default data.

Any ideas how to make such a script which will clear only the inputted data by the user.

解决方案

It's not the solution you want but apart from what Scott suggested, which is the most straightforward approach, you could make a copy of your sheet in the unedited state. In this copy have a script which will just copy and paste the info into the sheet that the user fills in.

Then if you make changes you just need to update the template sheet and not the script.

This is a very basic script but should you'll get the idea.

function myFunction() {

  var app = SpreadsheetApp;

  var tempSheet = app.getActiveSpreadsheet().getSheetByName('Sheet1');
  var inputSheet = app.openById('-----ID OF INPUT SHEET----').getSheetByName('Sheet1');

  var tempData = tempSheet.getDataRange().getValues();

    inputSheet.getRange(1, 1, tempData.length, 
    tempData[1].length).setValues(tempData);
}

这篇关于如何创建一个清除电子表格中数据的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆