如何将电子表格移动到另一个电子表格的工作表中

时间:2018-03-08 03:59:33

标签: excel google-apps-script google-sheets

我正在尝试复制电子表格并粘贴到另一个电子表格中,我的代码是:

  var open_file = SpreadsheetApp.openById(sheets_files.getId());
  var sheet_old = open_file.getSheetByName('Sheet1').activate();
  var destination = folder_open.getFilesByName('HistoryGameLog').next();

  var values_old = open_file.getActiveSheet().getRange('A1:S50').getValues();

  var destination_sheets = SpreadsheetApp.open(destination);

  //destination_sheets.insertSheet();
  var sheet_new = destination_sheets.getSheetByName('Sheet6').getRange('A1:S50');

  sheet_new.setValue(sheet_old);

但是当我检查新纸张时,它会显示所选范围内的所有“纸张” 请帮忙

1 个答案:

答案 0 :(得分:0)

您无需手动选择范围,然后在目的地设置值,您只需复制目的地中的整个工作表,如下所示:

var source = SpreadsheetApp.openById('SOURCE_ID_GOES HERE');
var sheet = source.getSheetByName('Sheet1');

var destination = SpreadsheetApp.openById('DESTINATION_ID_GOES HERE');
sheet.copyTo(destination);

参考:https://developers.google.com/apps-script/reference/spreadsheet/sheet#copytospreadsheet