Reputation: 115
I am creating a form using Google Sheets and have been using Google Apps Script to create buttons for the form. I was just writing to query why whenever I use the script below, the link that SHOULD create the PDF doesn't show as a link at all, just the word 'This' and nothing else, not hyperlinked or anything.
Here is the script:
function printPdf() {
SpreadsheetApp.flush();
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var gid = sheet.getSheetId();
var pdfOpts = '&size=A4&fzr=false&portrait=true&fitw=true&gridlines=false&printtitle=false&sheetnames=false&pagenum=UNDEFINED&attachment=false&gid='+gid;
var row2 = 56;
var printRange = '&c1=0' + '&r1=0' + '&c2=7' + '&r2='+row2; // B2:APn
var url = ss.getUrl().replace(/edit$/, '') + 'export?format=pdf' + pdfOpts + printRange;
var app = UiApp.createApplication().setWidth(100).setHeight(25);
app.setTitle('Click the link below to open as PDF');
var link = app.createAnchor('Open PDF', url).setTarget('_new');
app.add(link);
ss.show(app);
}
This works when I use one Google account but whenever I use any other accounts, the link doesn't work. My manager also tried with his Google account once I had shared it with him and it does not work for him either. The script has all the authoritative permissions needed to work and I can't spot any permission differences between one Google account that works and one that doesn't. I have even tried transferring ownership of the sheet to an account that does not work and still no luck. Any thoughts?
Upvotes: 0
Views: 207
Reputation: 1595
First time running your script on a new spreadsheet it shows the link fine for me. I would consider switching to html service as ui is deprecated.
UiApp API is deprecated.Expand
File: Code Line: 15
Anchor API is deprecated.Expand
File: Code Line: 18
UiInstance API is deprecated.Expand
File: Code Line: 15
Upvotes: 1