【发布时间】:2022-01-07 17:47:05
【问题描述】:
我使用谷歌电子表格创建发票并通过电子邮件以 PDF 格式发送它们,它运行良好,我的电子表格是每年一次的,所以每年新的一年我都会创建另一个,我从 2021 年开始的所有电子表格仍然可以正常工作,但是当我尝试打印或导出 PDF 时,我为 2022 年创建的所有新页面都在文档末尾添加了额外的空白页。空白页数取决于工作表上的空白行数,但我之前没有这个问题,即使工作表有 1000 行,如果发票只有 1 页 PDF/Print 只会生成1 页,现在如果工作表有 1000 行,它会生成 19 个空白页。
任何人有同样的问题或解决方案?
例如链接:Spreadsheet link
尝试打印或下载页面,您将看到生成的空白页面。
function savePDF() {
const ssh = SpreadsheetApp.getActiveSpreadsheet();
const invoice = ssh.getSheetByName('invoice');
const request = {
"method": "GET",
"headers":{"Authorization": "Bearer
"+ScriptApp.getOAuthToken()},
}
const key = ssh.getId();
const bogus = DriveApp.getRootFolder();
const fetch='https://docs.google.com/spreadsheets/d/'
+ key
+'/export?format=pdf&gid='
+ invoice.getSheetId()
+
'&size=letter&portrait=true
&printtitle=false
&pagenum=CENTER
&sheetnames=false
&gridlines=false
&top_margin=0.25
&bottom_margin=0.50&left_margin=0.25
&right_margin=0.25';
const name = "invoice.pdf";
let pdf = UrlFetchApp.fetch(fetch, request);
pdf = pdf.getBlob().setName(name);
const fold = "Folder ID goes here";
const folder = DriveApp.getFolderById(fold);
const file = folder.createFile(pdf);
}
【问题讨论】:
-
如何通过脚本或
file -> download -> pdf -> export选项导出工作表? -
通过脚本,但我在打印工作表时注意到同样的问题,最后会生成空白页。我记得大约 5 年前遇到过同样的问题,但它已修复,现在又回来了。
-
您能否在@Leo 中加入您的脚本?
-
下面的答案是解决问题的最快方法。或者您总是可以在打印之前先隐藏空白行。
标签: pdf google-sheets