Google工作表从另一个工作表ID创建pdf

嗨,如何修改此代码以从另一个工作表(而不是活动的打开工作表)创建PDF文件。 这是我正在使用的部分代码,它可以工作,但是我想根据另一个工作表ID创建PDF

谢谢

   var source = SpreadsheetApp.getActiveSpreadsheet();
   var spreadsheet = spreadsheetId ? SpreadsheetApp.openById(spreadsheetId) : SpreadsheetApp.getActiveSpreadsheet();
   var spreadsheetId = SpreadsheetApp.getActiveSpreadsheet().getId();
   var ticketnum = source.getSheetByName("Print Page").getRange('X1').getValue();
   var body = 'Attached is your copy'
   var Client = source.getSheetByName("Print Page").getRange('O5').getValue();
   var Cons = source.getSheetByName("Print Page").getRange('T4').getValue() ;
   var jobN = source.getSheetByName("Ticket PDF").getRange('G9').getValue() ;
   var mailTo = source.getSheetByName("Print Page").getRange('Z1').getValue() ;
   var folder = DriveApp.getFoldersByName('Ticket').next();
   var token = ScriptApp.getOAuthToken();
   var ssID = spreadsheetId;
   var url = "https://docs.google.com/spreadsheets/d/"+ssID+"/export"+
                                                    "?format=pdf&"+
                                                     '&portrait=true' + 
                                                     '&fzr=true' +  
                                                     '&fitw=True' + 
                                                     //'&scale=4' +
                                                     '&top_margin=0.25' + 
                                                     '&bottom_margin=0.25' + 
                                                     '&left_margin=0.25' +
                                                     '&right_margin=0.25' +
                                                     '&horizontal_alignment=CENTER' +  
                                                     '&gridlines=false'+
                                                     '&sheetnames=False';



     var response = UrlFetchApp.fetch(url, {
    headers: {
        'Authorization': 'Bearer ' + token
      }
    });

    var pdf = response.getBlob().setName( Client + "  " + ticketnum + " @ " + jobN + "  "  + '.PDF');
    folder.createFile(pdf)