使用Google Apps脚本中的自定义页眉或页脚将Google表格导出为PDF [英] Exporting Google Sheet as PDF with Custom Headers or Footers in Google Apps Script
问题描述
我想知道如何将自定义页眉或页脚添加到使用Google Apps脚本从Google表格导出的PDF中.我想在页脚中添加我的公司专有和机密"在页面中心.
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.
此功能可以从表格正常导出为PDF(即,文件»下载为»PDF»页眉和页脚»编辑自定义字段),但是我不知道如何使用URL参数进行复制.我也尝试过设置'&sheetnames=true&printtitle=true'
,但是这会将工作表名称和电子表格名称放在页眉而不是页脚中.
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.
我可以使用其他URL参数来控制这些自定义字段吗?
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
目标页脚:
推荐答案
我认为解决方法是:
- 创建一个新文档
- 插入标题
- 复制电子表格的内容
- 插入页脚
- 将新文件导出为PDF
- 删除新文件
这篇关于使用Google Apps脚本中的自定义页眉或页脚将Google表格导出为PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!