My code to get the Url (from a new worksheet that has been copied)
DriveApp.getFileById(sheet.getId()).makeCopy(nom,destFolder).getUrl();
var htmlOutput = HtmlService.createHtmlOutput('<a href="https://docs.google.com/spreadsheets/d' + '/" target="_blank">' + fileUrl + '</a>')
.setWidth(350).setHeight(50);
SpreadsheetApp.getUi().showModalDialog(htmlOutput,'Flowcalculator');
The Html shows the correct Url for the new file except it has an ending ....../edit?usp=drivesdk.
Do I need to write a 'format' function to delete the ?usp=drivesdk. or change the suffix to 'share' (I want the user to be able to open the file from the ModalDialog by clicking on the Url
I think that in your situation, even when https://docs.google.com/spreadsheets/d/{spreadsheetId}/edit?usp=drivesdk
is used as the hyperlink for opening the Spreadsheet, the link can be used.
I thought that in your script, '<a href="https://docs.google.com/spreadsheets/d' + '/" target="_blank">' + fileUrl + '</a>'
is required to be modified. In this case, the URL is https://docs.google.com/spreadsheets/d/
. This cannot be used.
If you want to open the copied Spreadsheet by clicking the link on the dialog, how about the following modification?
var fileUrl = DriveApp.getFileById(sheet.getId()).makeCopy(nom, destFolder).getUrl();
var htmlOutput = HtmlService.createHtmlOutput(`<a href="${fileUrl}" target="_blank">${fileUrl}</a>`).setWidth(350).setHeight(50);
SpreadsheetApp.getUi().showModalDialog(htmlOutput, 'Flowcalculator');
In this case, please declare the variables of sheet
, nom
, and destFolder
.
If you want to use https://docs.google.com/spreadsheets/d/{spreadsheetId}/edit?usp=sharing
instead of https://docs.google.com/spreadsheets/d/{spreadsheetId}/edit?usp=drivesdk
, please modify as follows.
From
var fileUrl = DriveApp.getFileById(sheet.getId()).makeCopy(nom, destFolder).getUrl();
To
var fileUrl = DriveApp.getFileById(sheet.getId()).makeCopy(nom, destFolder).getUrl().replace("drivesdk", "sharing");