表格提交谷歌云打印

时间:2014-04-03 23:47:22

标签: google-apps-script google-sheets google-form google-cloud-print

我可以在提交Google表单时使用一些帮助来创建脚本。

提交表单后,脚本会自动将Google电子表格打印到基于Google Cloud的打印机,而不会显示打印对话框窗口。

我已阅读Google Cloud Print Info

脚本背后的想法很简单:

  • 用户填写表格
  • 然后提交表格
  • 脚本使用用户输入的信息更新单元格
  • 脚本然后打印到谷歌云打印机
  • 装运标签准备就绪

以下脚本将打印票证,但如何将打印机功能添加到POST请求中?

到目前为止我的代码:

function onsubmit(e) {
var pid = "123456789"; //place printer id here
var sheetid = "123456789"; //place sheet id here
var ss = SpreadsheetApp.getActiveSpreadsheet();  
var info = ss.getSheetByName('Form responses 1');  
var lastRow = info.getLastRow();  
var sheet = SpreadsheetApp.setActiveSheet(ss.getSheetByName('TICKET'))  

authorize();
var url = "https://www.google.com/cloudprint/submit?printerid="+pid+"&contentType=google.spreadsheet&content="+sheetid+"&title=PrintingTicket";
var options = {
  method: "post",
  oAuthServiceName : "print",
  oAuthUseToken : "always"
   };
info.hideSheet();
var response = UrlFetchApp.fetch(url, options);
return Utilities.jsonParse(response.getContentText());
}

function authorize() {
var oauthConfig = UrlFetchApp.addOAuthService("print");
var scope = "https://www.googleapis.com/auth/cloudprint";
oauthConfig.setConsumerKey("anonymous");
oauthConfig.setConsumerSecret("anonymous");
oauthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope);
oauthConfig.setAuthorizationUrl("https://accounts.google.com/OAuthAuthorizeToken");    
oauthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");  
}

0 个答案:

没有答案