• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

217
Views
I am writing a script to copy a file Url to an Html Output. The issue I am having is the Url code has the text '?usp=drivesdk' added to the Url

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

about 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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?

Modified script:

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");
      
about 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error