Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

google app script print button

I've been working on a survey for about a month now(this is my first google script project, also I should mention that it's a web based app), and I only have a few things left to do(Creating a print button is one of them). Before I go on, I will give you some info about the survey. There are 6 pages(Each page corresponds to a button-I'm using buttons instead of the menu because I found out about it recently...) and only 1 page can be viewed at a time.

The problem is that I need to create the print button...which will print all of the pages.

I've been looking for a google script example for about 3-4 days now and I can't find anything...If I didn't make it clear enough please let me know and I will try to give more details..

Dave

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
    function printPdf() {
    SpreadsheetApp.flush();
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getActiveSheet();

    var gid = sheet.getSheetId();

    var pdfOpts = '&size=A4&fzr=false&portrait=false&fitw=true&gridlines=false&printtitle=false&shee        tnames=false&pagenum=UNDEFINED&attachment=false&gid='+gid;


    var row2 = 29;
    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(200).setHeight(50);
    app.setTitle('Print this sheet');

    var link = app.createAnchor('Download PDF', url).setTarget('_new');

    app.add(link);

    ss.show(app);
     }

This is a code that worked for me. It's modified from another thread.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...