Home > Software engineering >  How do i paste into another file through app script
How do i paste into another file through app script

Time:08-19

I am using this code:

function copyInfo() {  
  var ss = SpreadsheetApp.getActiveSpreadsheet();  
  var copySheet = ss.getSheetByName("Product-analyse");  
  var pasteSheet = ss.getSheetByName("Blad18"); // get source range  
var source = copySheet.getRange(93,7,39,6);  // get destination range  
var destination = pasteSheet.getRange(pasteSheet.getLastRow() 1,1,39,6); // copy values to destination range  
source.copyTo(destination);  // clear source values
source.clearContent();
} 

  1. Now its pasting in "Blad18". Instead I want it to be pasted in another file.
  2. I tried adding {contentOnly: TRUE}. Though this didnt seem to work

I cannot figure this out unfortunately. Everything else is correctly set already.

Any help is greatly appreciated.

CodePudding user response:

Try this:

function copyInfo() {
  var ss = SpreadsheetApp.getActive();
  var csh = ss.getSheetByName("Sheet0");
  var psh = ss.getSheetByName("Sheet1");
  const cshsr = 2;
  var crg = csh.getRange(cshsr, 1, csh.getLastRow() - cshsr   1, csh.getLastColumn());
  var prg = psh.getRange(psh.getLastRow()   1, 1); 
  crg.copyTo(prg); 
}

CodePudding user response:

I believe what you want to do is copy from one spreadsheet file to another spreadsheet file. Here is an example

function copyInfo() {  
  var ssSource = SpreadsheetApp.getActiveSpreadsheet();  
  var copySheet = ssSource.getSheetByName("Product-analyse"); 
  var ssPaste = SpreadsheetApp.openById("dfsfhsfhskfhaskjfhsjkfas"); // the id of the other spreadsheet
  var pasteSheet = ssPaste.getSheetByName("Blad18"); // get source range  
  var source = copySheet.getRange(93,7,39,6);  // get destination range  
  var destination = pasteSheet.getRange(pasteSheet.getLastRow() 1,1,39,6); // copy values to destination range  
  source.copyTo(destination);  // clear source values
  source.clearContent();
}

Reference

  • Related