提交时将数据复制到单独的文件中 [英] Copy data to a separate file when submitted

查看:35
本文介绍了提交时将数据复制到单独的文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道提交时是否可以将数据粘贴到另一个单独的文件(而不是选项卡)中.您认为有办法吗?

I'm wondering if when submitted, the data can be pasted to another separate file (and not tab). Do you think that there's a way?

您可以在此处访问文件: https://docs.google.com/spreadsheets/d/1FFlsfFyVyQobnbfAgQZA_r5IQeBhgOdK4cBpi5yo77U/edit?usp=sharing

You can access the file here : https://docs.google.com/spreadsheets/d/1FFlsfFyVyQobnbfAgQZA_r5IQeBhgOdK4cBpi5yo77U/edit?usp=sharing

以下代码:

function myFunction(){  
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var inputS = ss.getSheetByName("Input");
  var outputS = ss.getSheetByName("Output");
  var inputRng = inputS.getRange("A2:I2");
  var values = inputRng.getValues();
  inputRng.clearContent(); // clear input range       
  outputS.getRange(outputS.getLastRow()+1, 1, 1, values[0].length).setValues(values);
}

推荐答案

说明:

您可以使用 openById(id)通过其ID访问其他电子表格文件.如文档所述:

You can use openById(id) to access a different spreadsheet file by its id. As the documentation states:

例如,URL中的电子表格ID https://docs.google.com/spreadsheets/d/abc1234567/edit#gid = 0 是"abc1234567".

For example, the spreadsheet ID in the URL https://docs.google.com/spreadsheets/d/abc1234567/edit#gid=0 is "abc1234567".

,并假设目标电子表格具有名为"Output" 的工作表,则以下代码将起作用.否则,将其更改为目标工作表的名称.

and assuming that the target spreadsheet has a sheet named "Output" then the following code will work. Otherwise, change it to the name of the target sheet.

解决方案:

function ScriptBS() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var ts = SpreadsheetApp.openById(id); // put here the id of the target spreadsheet file
  var inputS = ss.getSheetByName("Input");
  var outputS = ts.getSheetByName("Output"); // get sheet Output of the target spreadsheet file
  var inputRng = inputS.getRange("A2:I2");
  var values = inputRng.getValues();
  inputRng.clearContent(); // clear input range       
  outputS.getRange(outputS.getLastRow()+1, 1, 1, values[0].length).setValues(values);
}

这篇关于提交时将数据复制到单独的文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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