'To copy a specified tab from one sheet and directly copy it over to another destination tab of another google sheet and have this occur on edits

need some help here. I have a master google sheet(Master Trix) that has several tabs.

Most of them contains private information, so i have to import a specific tab("Numbers") to another specific tab("Test")of another spreadsheet("Destination Source") that is for public view so that i can share it on google site. Edits will be made often on the master trix's tab("Numbers") and has to be reflected upon edit on tab("Test")of another spreadsheet("Destination Source")

I have tried importrange but it only copy the values to a destination tab of another spreadsheet.

Problem 1: The source tab has several links, images and formatting that i would need it on the destination. Problem 2: My management will update the master source tab and would like the destination to be updated automatically as well, with all formatting and links attached. I understand that google app script might be able to help.

I have tried the following:

function copytabtodestination() {

 var source = SpreadsheetApp.getActiveSpreadsheet();

 var sheet = source.getSheets()[0];

 var destination = SpreadsheetApp.openById("1dKMZhXlCeoaP92kmAlFUq1NgYo38fK_HryCfJ8jBzZ8");

 sheet.copyTo(destination);
}

But it creates a new tab that states "copy of Sample: Restriction Updates" . - Not the specific tab("Numbers") that is supposed to be reflected.Is there any way i can get it reflected in the "test" tab instead and changes will be updated upon edits?

Master trix: https://docs.google.com/spreadsheets/d/1Uhcq-dztXqZH9hEbF1-Ho7Wr5IQ1yTp3-VDVW5D-bpc/ Destination Source: https://docs.google.com/spreadsheets/d/1dKMZhXlCeoaP92kmAlFUq1NgYo38fK_HryCfJ8jBzZ8/

Thanks a million.



Solution 1:[1]

Copy Sheet Numbers to another Spreadsheet and Name it Numbers

function copyto() {
  const dssid = "1dKMZhXlCeoaP92kmAlFUq1NgYo38fK_HryCfJ8jBzZ8";
  const ss = SpreadsheetApp.getActive()
  const sssid = ss.getId();
  const sh = ss.getSheetByName('Numbers');//you can change this to another name if you wish to replace another sheet
  const sshid = sh.getSheetId();
  const options = {"method": "post","headers": { "Authorization": "Bearer " + ScriptApp.getOAuthToken() },"payload":{ "destinationSpreadsheetId": "" + dssid }};
  const url = `https://sheets.googleapis.com/v4/spreadsheets/${sssid}/sheets/${sshid}:copyTo`;
  let r = UrlFetchApp.fetch(url,options);
  let title = JSON.parse(r.getContentText()).title;
  const dss = SpreadsheetApp.openById(dssid);
  let s = dss.getSheetByName(sh.getName());
  if(s)dss.deleteSheet(s);//deletes old numbers if present
  dss.getSheetByName(title).setName(sh.getName());//rename sheet to original sheet name
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1