简体   繁体   English

是否可以将数据范围从一个电子表格复制到另一个电子表格?

[英]Is possible to copy a data range from one spreadsheet to another?

function transferDataToDataBase(){
    
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    
    var DB = SpreadsheetApp.openById("SHEET ID");
    
    var SCPM_Input = ss.getSheetByName("Report")[0];
    
    var history_Input = DB.getSheetByName(Database);
    
    var blankRow = history_Input.getLastRow();
    
    SCPM_Input.getRange(("A2:T").copyTo(history_Input.getRange(blankRow+1,1,blankRow+1,20));
    
}

Question:问题:

  1. The last line has an error at ";", don't know how to fix it.最后一行在“;”处有错误,不知道如何解决。 It said the syntax error;它说语法错误;
  2. It seems copy To only works for transferring from one sheet to another in the same spreadsheet, but not in between spread sheet.似乎 copy To 仅适用于在同一个电子表格中从一张工作表转移到另一张工作表,但不适用于电子表格之间。 Is there a way to copyTo between spreadsheets?有没有办法在电子表格之间复制到?

Many thanks.非常感谢。

If you want to copy the formatting as well then copy the entire sheet/tab and then use copyTo() to copy the range and then delete the copied sheet.如果您还想复制格式,请复制整个工作表/选项卡,然后使用 copyTo() 复制范围,然后删除复制的工作表。 Or if you just want the data use getValues() and setValues();或者,如果您只想要数据使用 getValues() 和 setValues();

This is part of the problem:这是问题的一部分:

var SCPM_Input = ss.getSheetByName("Report")[0]; because the index zero at the end should not be there and you cannot have sheet.getLastRow() + 1 number of rows in a sheet as shown in the next row.因为最后的索引零不应该在那里,并且您不能在工作表中有 sheet.getLastRow() + 1 行数,如下一行所示。

SCPM_Input.getRange(("A2:T").copyTo(history_Input.getRange(blankRow+1,1,blankRow+1,20));

And copyTo doesn't work between spreadsheets.并且 copyTo 在电子表格之间不起作用。

There is an update: Since the database will be used by multiple users.有一个更新:由于数据库将被多个用户使用。 I set up a standalone database.我建立了一个独立的数据库。 I copied my "Report" sheet from spreadsheet 1 to spreadsheet 2. It will create a sheet "copy of Report".I rename, copied to Database sheet and delete it.我将我的“报告”表从电子表格 1 复制到电子表格 2。它将创建一个“报告副本”表。我重命名,复制到数据库表并删除它。

Feel free to discuss if there is an easier way to do it.随意讨论是否有更简单的方法来做到这一点。 Thanks.谢谢。

// transfer the report to DataBase Spreadsheet // 将报告传输到数据库电子表格

function transferDataToDataBase(){函数 transferDataToDataBase(){

var ss = SpreadsheetApp.getActiveSpreadsheet(); var ss = SpreadsheetApp.getActiveSpreadsheet();

var db = SpreadsheetApp.openById('spreadsheet ID') var db = SpreadsheetApp.openById('电子表格 ID')

var scpm_Input = ss.getSheetByName("Report"); var scpm_Input = ss.getSheetByName("报告");

scpm_Input.copyTo(db); scpm_Input.copyTo(db);

Utilities.sleep(3000);实用程序.sleep(3000);

db.getSheetByName('copy of report').setName('Import') db.getSheetByName('报告副本').setName('导入')

var history_Input = db.getSheetByName('Database'); var history_Input = db.getSheetByName('Database');

var blankRow = history_Input.getLastRow(); var blankRow = history_Input.getLastRow();

var target = db.getSheetByName('Import'); var target = db.getSheetByName('Import');

target.getRange("A2:T").copyTo(history_Input.getRange(blankRow+1,1,blankRow+1,20)); target.getRange("A2:T").copyTo(history_Input.getRange(blankRow+1,1,blankRow+1,20));

history_Input.getRange(blankRow+1,21).setValue(new Date()).setNumberFormat("yyyy-mm-dd h:mm") //update the date and time history_Input.getRange(blankRow+1,21).setValue(new Date()).setNumberFormat("yyyy-mm-dd h:mm") //更新日期和时间

db.deleteSheet(target); db.deleteSheet(目标);

} }

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

相关问题 将范围从一个电子表格复制到另一个 - Copy a range from one spreadsheet to another 将动态范围从一个电子表格复制到另一个使用getfileid调用的电子表格 - copy dynamic range from one spreadsheet to another spreadsheet called with getfileid 将数据从一个电子表格文件复制到另一个 - Copy data from one spreadsheet file to another 在编辑时将数据从一个电子表格复制到另一个电子表格 - Copy data from one spreadsheet to another on edit Google脚本会根据日期将范围从一个电子表格复制到另一个电子表格 - Google scripts copy range from one spreadsheet to another based on date 将过滤后的范围从一个电子表格复制到另一个 - Google 应用脚本 - Copy filtered range from one spreadsheet to another - Google app script 根据过滤范围将数据从电子表格复制到另一个电子表格 - Copy data from a SpreadSheet to another based on filtered range 将范围从另一个电子表格复制到另一个 - Copy a range from another spreadsheet to another 将数据从一张纸复制到另一张电子表格,但不包括特定的列 - Copy data from one sheet to another spreadsheet exclude specific columns 不使用导入范围功能将数据从一个电子表格导入到另一个电子表格 - Importing data from one spreadsheet to another without the import range function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM