0

基本的なスクリプトが正常に動作しています。それは、GoogleシートをPDFに変換し、PDFでメールします。PDFマージン - Google Script

私の質問は、PDFの余白を調整するにはどうすればいいですか?ページに合わせてPDFを設定する必要があります。私はそれが間隔を捨てるので、シートのサイズを変更することはできません。

/* Email Google Spreadsheet as PDF */ 
function PDF() { 

    // Send the PDF of the spreadsheet to this email address 
    var email = "gmail.com"; 

    // Get the currently active spreadsheet URL (link) 
    var ss = SpreadsheetApp.openByUrl(
    'https://docs.google.com'); 

    // Subject of email message 
    var subject = "PAR - " + ss.getRange("A6:A6").getValue() +" - "+ ss.getRange("A5:A5").getValue(); 

    // Email Body can be HTML too 
    var body = "Name - " + ss.getRange("A6:A6").getValue() +" - "+ ss.getRange("A5:A5").getValue(); 

    var blob = DriveApp.getFileById(ss.getId()).getAs("application/pdf"); 

    blob.setName("Name - " + ss.getRange("A6:A6").getValue() +" - "+ ss.getRange("A5:A5").getValue() + ".pdf"); 

    // If allowed to send emails, send the email with the PDF attachment 
    if (MailApp.getRemainingDailyQuota() > 0) 
    GmailApp.sendEmail(email, subject, body, { 
     htmlBody: body, 
     attachments:[blob] 
    }); 
} 

私はこのようなスクリプトを見たことがありますが、それを自分のスクリプトで動作させる方法を理解できません。

var url_ext = 'exportFormat=pdf&format=pdf'  // export as pdf/csv/xls/xlsx 
    + '&size=letter'      // paper size legal/letter/A4 
    + '&portrait=false'     // orientation, false for landscape 
    + '&fitw=true&source=labnol'   // fit to page width, false for actual size 
    + '&sheetnames=false&printtitle=false' // hide optional headers and footers 
    + '&pagenumbers=false&gridlines=false' // hide page numbers and gridlines 
    + '&fzr=false'       // do not repeat row headers (frozen rows) on each page 
    + '&gid=';        // the sheet's Id 
+0

...あなたは余白を調整できるパラメータが表示されません。 [ドライブサービス](https://developers.google.com/apps-script/reference/drive/)を確認することはできますが、まだこの機能については言及されていないようです。 – noogui

答えて

0

私は同じ問題を抱えていますが、余白も取り除きたいと思います。どんな助けでもありますが、あなたが上で言及している部分を含む私の作業スクリプトです。 しかし、私は、私はAppsスクリプトがまだわき提供されているデフォルトの設定からのようスケーリングサポートと思ういけない

function CreaPDF() { 
 

 
    var report = SpreadsheetApp.getActive();    
 
    var pdfName = "ReportXXX"; 
 
    var sheetName = "Sheet1"; 
 
    var sourceSheet = report.getSheetByName(sheetName); 
 

 
    SpreadsheetApp.getActiveSpreadsheet().toast('Creating the PDF'); 
 

 
    // export url 
 
    var url = 'https://docs.google.com/spreadsheets/d/'+report.getId()+'/export?exportFormat=pdf&format=pdf' // export as pdf/csv/xls/xlsx 
 
    + '&size=A4'       // paper size legal/letter/A4 
 
    + '&portrait=false'      // orientation, false for landscape 
 
    + '&fitw=true'      // fit to page width, false for actual size 
 
    + '&sheetnames=false&printtitle=false' // hide optional headers and footers 
 
    + '&pagenumbers=false&gridlines=false' // hide page numbers and gridlines 
 
    + '&fzr=false'       // do not repeat row headers (frozen rows) on each page 
 
    + '&gid='+sourceSheet.getSheetId(); // the sheet's Id 
 

 
    var token = ScriptApp.getOAuthToken(); 
 

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

 
    var theBlob = response.getBlob().setName(pdfName+'.pdf'); 
 
    
 
    //var attach = {fileName:'Monthly Report.pdf',content:pdf, mimeType:'application/pdf'}; 
 
    
 
    var name = report.getRange("H1:H1").getValues(); // Get Name 
 
    var emailTo = report.getRange("H2:H2").getValues(); // Get email 
 
    var period = report.getRange("H3:H3").getValues(); // Get Reporting Period 
 
    var subject = " - TEST Monthly Report - " + period; // Construct the Subject Line 
 
    var message = "Hi " + name + ", here is your latest report for " + period; // email body text 
 

 
    // Send the freshly constructed email 
 
    MailApp.sendEmail(emailTo, subject, message, {attachments:[theBlob]}); 
 

 

 
}

+0

*「何か助けですか?」とはどういう意味ですか? – Pang

+0

これらは、余白を0に設定するパラメータです。「top_margin = 0&left_margin = 0&right_margin = 0&bottom_margin = 0」 – tmh

関連する問題