Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

93
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

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