gpt4 book ai didi

pdf - 导出为 PDF 时更改文档方向

转载 作者:行者123 更新时间:2023-12-04 19:40:26 25 4
gpt4 key购买 nike

我有这个脚本,可以定期通过电子邮件将电子表格的内容发送给所有协作者。

function myFunction() {
var document = SpreadsheetApp.openById("123documentid456");

var editors = document.getEditors();
for(var i = 0; i < editors.length; i++){
MailApp.sendEmail(editors[i].getEmail(), "Subject", "Some message", {
attachments : [document.getAs(MimeType.PDF)]
});
}
}

它创建一个 PDF 并通过电子邮件发送。问题是内容不能很好地显示,因为 PDF 的方向是纵向的。有什么办法可以让它导出为风景吗?

最佳答案

来自 here ,这段代码可以帮助

*************************************************

function savePDFs() {
SpreadsheetApp.flush();

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();

var url = ss.getUrl();

//remove the trailing 'edit' from the url
url = url.replace(/edit$/,'');

//additional parameters for exporting the sheet as a pdf
var url_ext = 'export?exportFormat=pdf&format=pdf' + //export as pdf
//below parameters are optional...
'&size=letter' + //paper size
'&portrait=false' + //orientation, false for landscape, true for portrait
'&fitw=true' + //fit to width, false for actual size
'&sheetnames=false&printtitle=false&pagenumbers=false' + //hide optional headers and footers
'&gridlines=false' + //hide gridlines
'&fzr=false' + //do not repeat row headers (frozen rows) on each page
'&gid=' + sheet.getSheetId(); //the sheet's Id

var token = ScriptApp.getOAuthToken();

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

var blob = response.getBlob().setName(sheet.getName() + '.pdf');

//from here you should be able to use and manipulate the blob to send and email or create a file per usual.
//In this example, I save the pdf to drive

DocsList.createFile(blob);
//OR DriveApp.createFile(blob);
}

*************************************************

注意这一点:'&portrait=false' +//orientation, false for landscape, true for portrait

关于pdf - 导出为 PDF 时更改文档方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35909624/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com