簡體   English   中英

將動態范圍從一個電子表格復制到另一個使用getfileid調用的電子表格

[英]copy dynamic range from one spreadsheet to another spreadsheet called with getfileid

我正在嘗試執行以下操作:

  • 循環瀏覽“客戶”中的“ A”列,並獲得相應的工作表名稱。
  • 獲取工作表並將工作表中所有使用的范圍(例如(A; B; C; etc))復制到B列中引用的特定文件。

這是我到目前為止編寫的代碼:

function updatefile() {
  var ss = SpreadsheetApp.getActive();
  var sh = ss.getSheetByName('CUSTOMER')
  var data = sh.getRange("A2:B12").getValues(); // get the range of non empty cells
  for (var i = 1; i < data.length; i++) {
    var source = ss.getSheetByName(data[i][0]);
    var range = source.getRange('C3:M1003'); //assign the range you want to copy
    var data = range.getValues();

    var destination = SpreadsheetApp.openById(data[i][1]); // open the corresponding file by using the file id in the second column 
    var destbodya = destination.getSheetByName('UPDATE ON ORDERS');
    destbodya.getRange(ts.getLastRow()+1, 1,49,7).setValues(data); //you will need to define the size of the copied data see getRange()
  }
}

鏈接到我的樣本電子表格

經過大量的搜索和試驗,我終於可以使用它了。 對於那些面臨這些挑戰的人。 干杯

function updatefile() {
  var ss = SpreadsheetApp.getActive();
  var sh = ss.getSheetByName('CUSTOMER')
  var data = sh.getRange("A2:B73").getValues(); // get the range of non emmpty cells
  for (var i = 1; i < data.length; i++) {
    if (data[i][0] != '') {
      var source = ss.getSheetByName(data[i][0]);
      var range = source.getRange('C3:M1003'); //assign the range you want to copy
      var valuedata = range.getValues();

      //var destination = SpreadsheetApp.openById("xxxxxxxxxxxxrrrrrsomeID"); // enter file ID directly or the nest line
      var destination = SpreadsheetApp.openById(data[i][1]); // Iterate through the range and open the corresponding file by using the file id in the secound column 
      var dest_1body = destination.getSheetByName('blah blah sheetname'); // first sheet destination to copy data to
      dest_1body.getRange("A2:K1002").setValues(valuedata); //you will need to define the size of the copied data see getRange()

      var destination = SpreadsheetApp.openById(data[i][1]); // open the coresponding file by using the file id in the secound column
      var dest_2body = destination.getSheetByName('blah blah sheetname'); // second sheet to copy same data to

      dest_2body.getRange("A28:K1028").setValues(valuedata); //you will need to define the size of the copied data see getRange()
    }
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM