0

I need to copy paste a range from template sheet file to current working sheet file. I understand from the below code, that is not possible.

Is it possible to achive this using Sheets API advanced service?

I actually need to copy paste cell widths, formatting, mergedcells etc from template file range to current file

I have tried with

function copyToMySheetFromTemplateFileRange()
{
  var ss = SpreadsheetApp.getActiveSpreadsheet()
  var sheet = ss.getActiveSheet();
  var tss = SpreadsheetApp.openById(ID_OF_TEMPLATE_SPREADSHEET);
  var tsheet = tss.getSheetByName("SHEET_A")
  
  tsheet.getRange(1, 1, sheet.getMaxRows(), sheet.getMaxColumns())
  var newSheet = ss.insertSheet(1);
  newSheet.getRange(2, 1).activate();
  tsheet.getDataRange().copyTo(newSheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);

}
Code Guy
  • 3,059
  • 2
  • 30
  • 74
  • You can try something like [this](https://stackoverflow.com/a/19791578/11225291) . – Marios Dec 17 '20 at 13:21
  • No, My idea is to copy range with formatting and I do not want to bring the template sheet to current file. – Code Guy Dec 17 '20 at 13:25
  • You want to copy both values and formatting or just formatting? – Marios Dec 17 '20 at 13:29
  • 1
    also in your code you insert a new sheet. What difference does it make if you bring the template sheet to your file? (given that you copy the full data range).... But even if you don't want to do that, you can copy the template sheet, get the formatting/values and put them in the new sheet with your current code. – Marios Dec 17 '20 at 13:32
  • Bring the template and delete it after copying? – TheMaster Dec 17 '20 at 14:43
  • Does this answer your question? [Google Apps Script, copy one spreadsheet to another spreadsheet with formatting](https://stackoverflow.com/questions/19791132/google-apps-script-copy-one-spreadsheet-to-another-spreadsheet-with-formatting) – Rafa Guillermo Dec 17 '20 at 14:44

0 Answers0