Exporting Google Sheet as PDF with Custom Headers or Footers in Google Apps Script

落爺英雄遲暮 提交于 2019-12-03 09:57:26

问题


I'm wondering how to add custom headers or footers to a PDF that is exported using Google Apps Script from a Google Sheet. I would like to add a footer that says "My Company Proprietary and Confidential" in the center of the page.

This is functionality that is available in normal PDF export from Sheets (i.e. File » Download as » PDF » Headers & footers » EDIT CUSTOM FIELDS), but I don't know how to replicate it with URL parameters. I've also tried setting '&sheetnames=true&printtitle=true', but this puts the sheet name and spreadsheet name in the header instead of the footer.

Are there any additional URL parameters I can use to control these custom fields?

  var url = 'https://docs.google.com/spreadsheets/d/'+sourceSpreadSheet.getId()
  +'/export?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'                        // fit to page width, false for actual size
  + '&sheetnames=false&printtitle=false' // hide optional headers and footers
  + '&pagenum=CENTER&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
  + '&top_margin=0.45&left_margin=0.25&right_margin=0.25&bottom_margin=0.5'; // margins

Target Footer

来源:https://stackoverflow.com/questions/50025746/exporting-google-sheet-as-pdf-with-custom-headers-or-footers-in-google-apps-scri

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!