Skip to content

Instantly share code, notes, and snippets.

@neno-tech
Created April 26, 2022 05:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save neno-tech/59ba584dc4f8669ccb63e262a64cc895 to your computer and use it in GitHub Desktop.
Save neno-tech/59ba584dc4f8669ccb63e262a64cc895 to your computer and use it in GitHub Desktop.
โค้ด copy data from sheet to sheet
function copyData() {
importRange(
"xxx",
"yyy",
"xxx",
"yyy" );
}
function importRange(sourceID, sourceRange, targetID, targetRange) {
const sourceSS = SpreadsheetApp.openById(sourceID);
const sourceRng = sourceSS. getRange (sourceRange);
const sourceVals = sourceRng.getValues();
const targetSS = SpreadsheetApp.openById(targetID);
const targetRng = targetSS.getRange(targetRange);
const targetSheet = targetSS.getSheetByName(targetRng.getSheet().getName());
targetSheet.clear ()
const targetVals = targetSheet.getRange(
targetRng.getRow(),
targetRng.getColumn(),
sourceVals.length,
sourceVals[0].length
)
targetVals.setValues(sourceVals);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment