使用参数导出到PDF [英] Export to PDF with parameters
问题描述
曾经阅读过有关如何将工作表保存为PDF文件的信息,但我偶然发现此代码在以前很好用,但是现在不会出现"uiapp已弃用"的错误.我怎样才能解决这个问题?顺便说一句,代码不是我的,我只是根据自己的喜好对其进行了调整.建议使用HTML服务.
Been reading about how to save sheet to a PDF file and I stumble to this code it works well before but now it won't been getting error of "uiapp deprecated". How can I fix this? BTW the codes not mine,I just tweak it to suit my preferences. It's suggesting to use HTML Services.
function PDF() {
SpreadsheetApp.flush();
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var gid = sheet.getSheetId();
var pdfOpts = '&size=letter&fzr=false&portrait=true&fitw=false&gridlines=false&scale=1&top_margin=0.17&bottom_margin=0.17&left_margin=0.1&right_margin=0.1&printtitle=false&sheetnames=false&pagenum=UNDEFINED&attachment=false&gid='+gid;
var row2 = 66;
var printRange = '&c1=0' + '&r1=0' + '&c2=15' + '&r2='+row2; // B2:APn
var url = ss.getUrl().replace(/edit$/, '') + 'export?format=pdf' + pdfOpts + printRange;
var app = UiApp.createApplication().setWidth(300).setHeight(100);
app.setTitle('Print this sheet');
var link = app.createAnchor('Download PDF', url).setTarget('_new');
app.add(link);
ss.show(app);
};
推荐答案
此修改如何?我认为您的情况可能有几个答案.因此,请仅考虑其中之一.
How about this modification? I think that there might be several answers for your situation. So please think of this as just one of them.
在此修改中,我使用了类Ui的showModalDialog方法.
In this modification, I used the method of showModalDialog of Class Ui.
var app = UiApp.createApplication().setWidth(300).setHeight(100);
app.setTitle('Print this sheet');
var link = app.createAnchor('Download PDF', url).setTarget('_new');
app.add(link);
ss.show(app);
到:
var html = '<a href="' + url.replace(/&/g, "&") + '" target="_new">Download PDF</a>';
var userInterface = HtmlService.createHtmlOutput(html).setWidth(300).setHeight(100);
SpreadsheetApp.getUi().showModalDialog(userInterface, 'Print this sheet');
参考:
- Ui类
- Class Ui
Reference:
如果我误解了您的问题,请告诉我.我想修改它.
If I misunderstood your question, please tell me. I would like to modify it.
这篇关于使用参数导出到PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!