建立链接以PDF格式导出工作表 [英] Building link to export sheet as PDF

查看:94
本文介绍了建立链接以PDF格式导出工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试将特定的工作表导出为PDF以便邮寄,结果发现我需要它们采用特定的格式.我四处寻找要使用的代码,最终找到了这个代码: https://issuetracker.google. com/issues/36761058#comment24

I've been trying to export specific sheets as PDFs for mailing purposes, and found that I needed them to be in a specific format. I went around looking for code to use and ended up finding this: https://issuetracker.google.com/issues/36761058#comment24

尽管我已经合并了很多自己的代码,但是其中很大一部分与我上面发布的链接中的代码相同,并且除了一件事之外,它运行得很好.

Although I have incorporated quite a bit of my own code, a good chunk of it is the same as in the link I posted above, and it works quite well except for one thing.

如下面的代码所示,由于某些工作表中有很多列,因此我选择了适合的宽度为"false".但是,我得到的PDF总是适合宽度格式,而不是实际大小,因此实际上很难在打印时阅读.我已经尝试研究它,但是到目前为止,我的尝试都空手而归,所以我终于决定尝试在这里提问.

As seen in the code below, I've chosen to have fit width as "false" since some of my sheets have a lot of columns. However, the PDFs I get are always in the fit to width format, and not actual size, making it practically impossible to read should it be printed. I've tried to look into it, but my attempts so far have turned up empty-handed, so I've finally decided to try and ask here.

     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=A4' + //paper size 
  '&portrait=false' + //orientation, false for landscape 
  '&fitw=false' + //fit to width, false for actual size 
  '&sheetnames=true&printtitle=true&pagenumbers=true' + //hide optional headers and footers 
  '&gridlines=true' + //hide gridlines 
  '&fzr=false' + //do not repeat row headers (frozen rows) on each page 
  '&gid=' + spaceman.getSheetId();

  var token = ScriptApp.getOAuthToken(); 
    Logger.log("URL: " + url + url_ext);

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

对于解决该问题的任何帮助或建议将不胜感激.当然,如果需要澄清或在原始帖子中添加一些内容,那么我很乐意这样做.

Any help or suggestions on how to solve this issue of mine would be greatly appreciated. Of course, if something needs to be clarified or added to the original post then I would be happy to do so.

我一直对此很执着,所以我还没有对脚本做任何其他事情,今天只是再次测试了脚本,突然之间我得到的是实际尺寸,而不是fitw ,所以我想这可能是一个错误?

I've been really stuck on this so I haven't really done anything else to the script, just tested the script again today and suddenly I'm getting actual size instead of fitw, so I suppose it could've been a bug?

推荐答案

我不确定这是否是错误-但是,如果直接访问URL,则可以复制问题-

I am not sure if this is a bug- But if you access the URL direct, you can replicate your issue-

https://docs.google.com/spreadsheets/d/ADDYOURIDSSHERE/export?fitw=false&format=pdf

这篇关于建立链接以PDF格式导出工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆