简体   繁体   English

水平打印Google表格中的图表

[英]Print a chart from Google Sheets horizontally

I need to find ways of printing a chart as pdf/image/sheet horizontally . 我需要找到将图表水平打印为pdf / image / sheet的方法

I print automatically with code. 我会自动打印代码。

Now I am printing a pdf created out of a Spreadsheet tab but it always prints vertically despite options settings. 现在,我正在打印从“电子表格”选项卡创建的pdf,但是尽管有选项设置,但它始终会垂直打印。

It saves beautiful horizontal pdfs on Drive but then prints them vertically. 它将漂亮的水平pdf保存在云端硬盘上,然后垂直打印。

As I print statistics I need it to be horizontally. 当我打印统计信息时,我需要将其水平放置。

Here's my code with options: 这是我的带有选项的代码:

  var requestData = { "oAuthServiceName": "spreadsheets", "oAuthUseToken": "always", }; //spreadsheet id var ssID = ss.getId() //sheet id var sID = ss.getSheetByName("Print").getSheetId(); //creating pdf var pdf = UrlFetchApp.fetch("https://docs.google.com/spreadsheets/d/"+ssID+"/export?gid="+sID+"&portrait=false&size=letter&fitw=true&format=pdf",requestData).getBlob(); //folder to created pdf in var folder = DriveApp.getFolderById("1RseEezmGT2gSBS9rgdV0E2ggRD5O6dyu") //creating pdf in this folder with given name var file = folder.createFile(pdf).setName("Chart") var docID = file.getId() var printerID = "02f4280c-9e83-da7d-d5ff-ca0f25ca03e3" var docName = "Chart" //starts printing printGoogleDocument(docID, printerID, docName) 

And

 function printGoogleDocument(docID, printerID, docName) { var ticket = { version: "1.0", print: { color: { type: "STANDARD_COLOR", vendor_id: "Color" }, duplex: { type: "NO_DUPLEX" } } }; var payload = { "printerid" : printerID, "title" : docName, "content" : DriveApp.getFileById(docID).getBlob(), "contentType": "application/pdf", "ticket" : JSON.stringify(ticket) }; var response = UrlFetchApp.fetch('https://www.google.com/cloudprint/submit', { method: "POST", payload: payload, headers: { Authorization: 'Bearer ' + getCloudPrintService().getAccessToken() }, "muteHttpExceptions": true }); 

So I am using here an option portrait=false to print as a landscape. 所以我在这里使用了portrait=false的选项来打印为风景。 Doesn't work. 不起作用

Appreciate any solutions for horizontal printing. 感谢任何用于横向打印的解决方案。

Try including page_orientation in the ticket: 尝试在page_orientation中包含page_orientation

  var ticket = {
    version: "1.0",
    print: {
      color: {
        type: "STANDARD_COLOR",
        vendor_id: "Color"
      },
      duplex: {
        type: "NO_DUPLEX"
      },
      page_orientation: { //Added
        type:1//or type:"LANDSCAPE"
      }
    }
  };

References: 参考文献:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM