- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用页面参数(纵向/横向,...)
我对此进行了研究并找到了可能的解决方案 here .
有几个类似的解决方案,但只适用于旧版本的谷歌电子表格。
请考虑以下代码:
function exportAsPDF() {
//This code runs from a NEW version of spreadsheet
var oauthConfig = UrlFetchApp.addOAuthService("google");
oauthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
oauthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope=https://spreadsheets.google.com/feeds/");
oauthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
oauthConfig.setConsumerKey("anonymous"); oauthConfig.setConsumerSecret("anonymous");
var requestData = { "method": "GET", "oAuthServiceName": "google","oAuthUseToken": "always" };
var ssID1="0AhKhywpH-YlQdDhXZFNCRFROZ3NqWkhBWHhYTVhtQnc"; //ID of an Old version of spreadsheet
var ssID2="10xZX9Yz95AUAPu92BkBTtO0fhVk9dz5LxUmJQsJ7yPM"; //ID of a NEW version of spreadsheet
var ss1 = SpreadsheetApp.openById(ssID1); //Old version ss object
var ss2 = SpreadsheetApp.openById(ssID2); //New version ss object
var sID1=ss1.getActiveSheet().getSheetId().toString(); // old version sheet id
var sID2=ss2.getActiveSheet().getSheetId().toString(); // new version sheet id
//For Old version, this runs ok.
var url1 = "https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key="+ssID1+"&gid="+sID1+"&portrait=true"+"&exportFormat=pdf";
var result1 = UrlFetchApp.fetch(url1 , requestData);
var contents1=result1.getBlob();
var pdfFile1=DriveApp.createFile(contents1).setName("FILE1.pdf");
//////////////////////////////////////////////
var url2 = "https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key="+ssID2+"&gid="+sID2+"&portrait=true"+"&exportFormat=pdf";
var result2 = UrlFetchApp.fetch(url2 , requestData);
var contents2=result2.getBlob();
var pdfFile2=DriveApp.createFile(contents2).setName("FILE2.pdf");
}
"https://docs.google.com/spreadsheets/d/"+ssID2+"/export?gid="+sID2+"&portrait=true&format=pdf"
var url2 = "https://docs.google.com/spreadsheets/d/"+ssID2+"/export?gid="+sID2+"&portrait=true&format=pdf"
) 它再次失败并显示错误“无法为服务执行授权:google”。
https://docs.google.com/feeds
并设置它:
oauthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope=https://docs.google.com/feed/");
代码再次运行后,在
UrlFetchApp.fetch(url2 , requestData);
行发生了新的错误。 :“错误 OAuth”……我不知道如何继续……我已经测试了数百个变体,但没有很好的结果。
最佳答案
这是我的电子表格到 pdf 脚本。它适用于新的 Google 电子表格 API。
// Convert spreadsheet to PDF file.
function spreadsheetToPDF(id,index,url,name)
{
SpreadsheetApp.flush();
//define usefull vars
var oauthConfig = UrlFetchApp.addOAuthService("google");
var scope = "https://docs.google.com/feeds/";
//make OAuth connection
oauthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
oauthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope);
oauthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
oauthConfig.setConsumerKey("anonymous");
oauthConfig.setConsumerSecret("anonymous");
//get request
var request = {
"method": "GET",
"oAuthServiceName": "google",
"oAuthUseToken": "always",
"muteHttpExceptions": true
};
//define the params URL to fetch
var params = '?gid='+index+'&fitw=true&exportFormat=pdf&format=pdf&size=A4&portrait=true&sheetnames=false&printtitle=false&gridlines=false';
//fetching file url
var blob = UrlFetchApp.fetch("https://docs.google.com/a/"+url+"/spreadsheets/d/"+id+"/export"+params, request);
blob = blob.getBlob().setName(name);
//return file
return blob;
}
关于google-apps-script - 使用 pdf 选项使用 google 脚本将新版本的 google 电子表格导出(或打印)为 pdf 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21997924/
我这里有一个工作示例。 https://developers.google.com/google-apps/spreadsheets/我需要从用户的谷歌文档下载一些文件。 import com.goo
我需要您在以下方面的帮助: 假设我们有 3 个不同的组:(A、B、C) 我们在每个组中有几个值范围: (Eg. A has 0 - 100, 101 - 200 while B has 0 - 200
谁能告诉我有什么方法可以从 python 连接到电子表格吗?我想从表单中存储一些数据并将其提交到谷歌电子表格。请帮助解决这个问题。我必须遵循哪些步骤? 提前致谢... 最佳答案 连接到 Google
我正在尝试计算 2019 年给定时间范围内的月数。 我的数据如下所示: 我将开始日期和结束日期列的格式更改为“日期”。 “以月为单位的持续时间”和输出列具有数字格式。 我接近它如下: 如果开始日期(年
在设计上有一点问题,希望我能在这里寻求建议。接受 grails 可能是完全错误的工具,但这就是生活。 所以一直在努力开发一个网络应用程序,该应用程序基本上只是从谷歌电子表格中呈现大量信息并发回一些更新
我正在设计一个胖客户端(即非浏览器)Python 应用程序,它将与托管数据库进行通信。该应用程序的屏幕之一需要有一个网格/电子表格区域,允许显示多行数据、过滤、排序和更新多行信息。有人推荐一个具有此功
我在 Django 中有一个表单,可以将用户添加到 mySQL 数据库。然而,用户将不得不添加大量用户,并且一些信息将被复制和粘贴。所以我在想是否有一种方法可以有一个类似表单的电子表格,其中列标题是将
我在 Outlook VBA 中编写了一个程序,它根据 Excel 电子表格的内容创建一些电子邮件。一切正常,但是当程序终止时,我继续运行“EXCEL.EXE”进程,该进程会锁定电子表格,因此其他人无
如何使用公式来确定当前时区? 我使用的公式给出了意想不到的结果。 我的电子表格设置(文件 > 电子表格设置...): 时区: (GMT+01:00) 阿姆斯特丹 我使用的公式: =TEXT(NOW()
如何转换持续时间的小时数? 示例:在单元格 A1 中,我有 176 . 我希望单元格 A2 有 176:00:00 我想在 176 小时(持续时间)内转换数字 176。那可能吗?因为如果我在单元格中键
我收到了 4 个不同的采购订单,上面有一个随机的采购订单编号。 我仅在 A 列中填写采购订单号。 对于这个例子,我收到了下面列出的 4 个不同的采购订单。 采购订单 697533 - 2 项 采购订单
我需要编写循环遍历数据列的程序。根据单元格值和代表变量的每一列重置变量。 练习中的变量取决于循环的这些值。 如何在循环的每次迭代中将值增加 1 来循环遍历行? df=pd.DataFrame(r'C:
我正在做一些详尽的搜索,需要确定新域 (URL) 是否已经在电子表格中。但是,没有一个电子表格对象具有搜索功能,即在大多数文档对象中找到的 findText()。我觉得我错过了一些重要的东西。 我错过
我正在尝试在 Pandas 中导入一个 excel 电子表格,但由于数据“由用户在视觉上构建”以在视觉上对用户友好并且没有使用正确的数据结构,因此我遇到了一些问题。 结果,当在 Pandas 中作为数
我必须在 HTML 页面上显示多个图表,但我无法进行多个查询(直接在 google 电子表格上)。 实际上,我只是第一个查询显示的是谁。 我的代码: Page de pilotage
我使用以下代码作为将 html 网站上的用户输入数据发送到 Google 电子表格的方法: Javascript: function postContactToGoogle() { v
我有一个使用 Google Drive 和电子表格 API 的网站。我想要做的是,如果没有找到具有特定条件的电子表格,则在用户的 Google 云端硬盘上创建电子表格。该电子表格应该是我的 Googl
我目前链接到六个 Excel 电子表格,主要是因为用户在 Excel 中编辑数据更容易/更好(他们从未使用过 Access),而且任何更改都会立即反射(reflect),包括是否有新列添加后即可立即供
我正在努力通过 PowerShell 添加指向可变长度电子表格的链接,无论如何我都会遇到错误。这是我目前正在尝试制作的循环,它嵌套在一个 excel comobject 中, $sheet 代表 $e
在 Excel 电子表格中编写许多工作表可能需要一段时间。并行化它会很有帮助。 此代码运行良好,它使一个 Excel 电子表格在屏幕上弹出,其中包含四个名为 Sheet1、1、2 的工作表 和 3。
我是一名优秀的程序员,十分优秀!