Google フォームが送信されたときにスクリプトを作成するのに役立ちます。
フォームが送信されると、スクリプトは、印刷ダイアログ ウィンドウを表示することなく、Google スプレッドシートを Google クラウドベースのプリンターに自動的に印刷します。
Google クラウド プリント情報を読みました
スクリプトの背後にある考え方は単純です。
- ユーザーがフォームに記入する
- その後、フォームが送信されます
- スクリプトは、ユーザーが入力した情報でセルを更新します
- スクリプトはその後、Google クラウド プリンタに出力します
- 配送ラベルの準備ができました
以下のスクリプトはチケットを印刷しますが、プリンター機能を 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");
}