D
D
DervishJan2020-04-21 16:30:29
Google Apps Script
DervishJan, 2020-04-21 16:30:29

How to open a Table by reference after it has been created?

Greetings!
I want to use GAS to create a copy of the table, and then open it in a new browser tab for editing. Wrote this:

function creatCP(ssID,filename){
  var source = DriveApp.getFileById(ssID);
  var targetFolder = DriveApp.getFolderById(tagFolderID);
  var newFile = source.makeCopy(filename,targetFolder);
  var ss = newFile.getUrl();
  return ss;
  }
   .......
  var newFileUrl = creatCP(SourceLink,filename);
  var newSSopen = SpreadsheetApp.openByUrl(newFileUrl);
  SpreadsheetApp.setActiveSheet(newSSopen.getSheets()[1]);
}


It creates a copy under the right name in the right place, I get a url-link to a new file, but I don’t open a new table and switch to it. Where am I doing something wrong, please tell me!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ivanov, 2020-04-21
@oshliaer

Everything is pretty simple.
Pass ss value to function

/**
 * Open the url in a new tab
 * @param {string} url
 */
function openUrlInBrowser_(url) {
  const tmp = HtmlService.createTemplateFromFile('app');
  tmp.url = url;
  const htmlOutput = tmp.evaluate();
  SpreadsheetApp.getUi().showModelessDialog(htmlOutput, 'Opening url ...');
}

This function requires a file app.htmlin the project
/**
 * Open the url in a new tab
 * @param {string} url
 */
function openUrlInBrowser_(url) {
  const tmp = HtmlService.createTemplateFromFile('app');
  tmp.url = url;
  const htmlOutput = tmp.evaluate();
  SpreadsheetApp.getUi().showModelessDialog(htmlOutput, 'Opening url ...');
}

5e9f194323664331291861.gif
Full code https://github.com/contributorpw/google-apps-script...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question