【问题标题】:export range to next available row on different sheet将范围导出到不同工作表上的下一个可用行
【发布时间】:2022-06-15 19:57:21
【问题描述】:

我希望运行一个脚本,将一个范围导出到不同的谷歌工作簿和指定的工作表中,但导入到所述工作表上的下一个可用行。 我有下面的脚本运行良好,但需要目标表上的范围。 - 我需要它自动转到下一个可用行。

“取消!A:A”是我认为需要更改的内容,以便它自动导入到下一行可用。 非常感谢任何帮助

function runsies() {
 
  importRange(
    "****",  //Source ID -  e.g. 
    "Cancellations!A4:E17", // Source Range - e.g. "Task List!A2:G"
    "*****", // Destination ID - e.g.
    "Cancellations!A:A" // Destination Range Start - e.g. "Sheet1!B3"
  );
 
};
 
/**
* Imports range data from one Google Sheet to another.
* @param {string} sourceID - The id of the source Google Sheet.
* @param {string} sourceRange - The Sheet tab and range to copy.
* @param {string} destinationID - The id of the destination Google Sheet.
* @param {string} destinationRangeStart - The destintation location start cell as a sheet name and cell.
*/
function importRange(sourceID, sourceRange, destinationID, destinationRangeStart){
 
  // Gather the source range values
  const sourceSS = SpreadsheetApp.openById(sourceID);
  const sourceRng = sourceSS.getRange(sourceRange)
  const sourceVals = sourceRng.getValues();
 
  // Get the destiation sheet and cell location.
  const destinationSS = SpreadsheetApp.openById(destinationID);
  const destStartRange = destinationSS.getRange(destinationRangeStart);
  const destSheet = destStartRange.getSheet();
 
  // Clear previous entries.
  destSheet.clear();
 
  // Get the full data range to paste from start range.
  const destRange = destSheet.getRange(
      destStartRange.getRow(),
      destStartRange.getColumn(),
      sourceVals.length,
      sourceVals[0].length
    );
  
  // Paste in the values.
  destRange.setValues(sourceVals);
 
  SpreadsheetApp.flush();
};

【问题讨论】:

  • 在您的脚本中,似乎目标工作表已被destSheet.clear() 清除。所以,在这种情况下,我认为const destRange = destSheet.getRange(1, 1, sourceVals.length, sourceVals[0].length) 可能可以用作目标范围。但是,如果我误解了您的问题,我深表歉意。

标签: google-apps-script google-sheets


猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-02-27
  • 1970-01-01
  • 2023-01-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多