【问题标题】:download pdf from google sheet and从 google sheet 下载 pdf 和
【发布时间】:2022-06-14 04:07:50
【问题描述】:

我找到了这段代码,我可以在其中将 google sheet 下载为 pdf,但我想更改它以便选择另一个工作表,然后选择活动的工作表,并在代码在没有框的情况下运行后下载 pdf。

function PDF() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheetId = ss.getActiveSheet().getSheetId();
  var url = "https://docs.google.com/a/mydomain.org/spreadsheets/d/" + ss.getId() + "/export?exportFormat=pdf&gid=" + sheetId + "&access_token=" + ScriptApp.getOAuthToken();
  var str = '<input type="button" value="Download" onClick="location.href=\'' + url + '\'" >';
  var html = HtmlService.createHtmlOutput(str);
  SpreadsheetApp.getUi().showModalDialog(html, "Download_Report");
}

【问题讨论】:

  • 我必须为我糟糕的英语水平道歉。不幸的是,我无法理解I want to change it in order to chose another sheet then the active one and download the pdf once the code run without the box.。可以问一下具体情况吗?
  • 我的意思是我想在一张纸上运行这段代码,而不是我目前使用的那张
  • 感谢您的回复。从你的回复中,我提出了一个答案。你能确认一下吗?如果我误解了您的问题并且没有用处,我深表歉意。

标签: google-apps-script


【解决方案1】:

What I meant is I want to run this code on a sheet other then the one I am currently using为例,如果你想使用除活动表之外的其他表的sheetId,那么下面的修改如何?

发件人:

var sheetId = ss.getActiveSheet().getSheetId();

收件人:

当要使用工作表名称时,请进行如下修改。

var sheetId = ss.getSheetByName("Sheet2").getSheetId(); // Please set the sheet name like "Sheet2".

当您要使用工作表的索引时,请进行如下修改。在这种情况下,index = 1 是第二张纸。所以,第一张表的索引是0

var index = 1; // Please set the index of the sheet you want to use.
var sheetId = ss.getSheets()[index].getSheetId();
  • 当然,您可以直接输入您要使用的特定工作表ID。

参考资料:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-24
    相关资源
    最近更新 更多