Is there a way to create a pdf with google apps script that includes only a specific sheet of a spreadsheet?

后端 未结 7 1381
[愿得一人]
[愿得一人] 2020-12-15 14:43

In the spreadsheet app itself, you have the options to print only a specific sheet. You also can turn off the grid lines when creating the pdf from within the app. Is ther

相关标签:
7条回答
  • 2020-12-15 15:04

    this is a solution

    var blob = DriveApp.getFileById(idsheet).getAs("application/pdf");
    blob.setName("name".pdf");
    var dossier = DriveApp.getFolderById("0Bx71KaTqXxQPQUYyVEVyYkJ0bEU");
    dossier.createFile(blob);
    
    0 讨论(0)
  • 2020-12-15 15:06

    I simply hide the sheets that I don't want put in the pdf

    0 讨论(0)
  • 2020-12-15 15:07

    When you choose export to pdf, you get a messagebox with options. In the right side of this messagebox there are five checkboxes. Check the second one, then you will hide the gridlines in the export. I don't know the label of this checkbox, because I use another language than english.

    Good luck!

    - Robert

    0 讨论(0)
  • 2020-12-15 15:11

    Google apps script to create a pdf of a specific sheet of a spreadsheet.

    function generatePdf() {
        var originalSpreadsheet = SpreadsheetApp.getActive();
    
        var sourcesheet = originalSpreadsheet.getSheetByName("Sheet - Name");
        var sourcerange = sourcesheet.getRange('A1:G7');  // range to get - here I get all of columns which i want
        var sourcevalues = sourcerange.getValues();
        var data = sourcesheet.getDataRange().getValues();
    
        var newSpreadsheet = SpreadsheetApp.create("Spreadsheet to export"); // can give any name.
        var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
        var projectname = SpreadsheetApp.getActiveSpreadsheet();
        var sheet = sourcesheet.copyTo(newSpreadsheet);
        var destrange = sheet.getRange('A1:G7');
        destrange.setValues(sourcevalues);
        newSpreadsheet.getSheetByName('Sheet1').activate();
        newSpreadsheet.deleteActiveSheet();
    
        var pdf = DriveApp.getFileById(newSpreadsheet.getId());
        var theBlob = pdf.getBlob().getAs('application/pdf').setName("name");
    
        var folderID = "Folder Id"; // Folder id to save in a folder.
        var folder = DriveApp.getFolderById(folderID);
        var newFile = folder.createFile(theBlob);
    
        DriveApp.getFileById(newSpreadsheet.getId()).setTrashed(true); 
    }
    
    0 讨论(0)
  • 2020-12-15 15:13

    @rcknr, worked for me, more options below. (From: http://productforums.google.com/forum/#!msg/apps-script/wQvCF6yY1Qk/R0uyVmf-Xx0J )

    URL like this: https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=tOHm3f8tdIxf7tSZzWvBGiA&gid=0&size=legal&fitw=true&gridlines=false&portrait=false&exportFormat=pdf

    other settings

    fmcmd=12
    size=legal/A4
    fzr=true/false
    portrait=false/true
    fitw=true/false
    gid=0/1/2  
    gridlines=false/true
    printtitle=false/true
    sheetnames=false/true
    pagenum=UNDEFINED
    attachment=false/true  
    

    true/false where sometimes required, I could not use 0/1 instead.

    0 讨论(0)
  • 2020-12-15 15:19

    Unfortunately this currently isn't possible with Apps Script, but you can file a feature request on our issue tracker.

    0 讨论(0)
提交回复
热议问题