-2
나는 자동으로 이메일을 매일 발송하는 Google Script가 있습니다. 여러 개의 "가져 오기"기능이있는 다소 큰 Google 스프레드 시트입니다. 나는 완벽하게 작동하는 작은 스프레드 시트를 가지고있다. 그러나 큰 스프레드 시트에서 이메일이 사라지면 데이터는 계속로드됩니다. 데이터가 다음 함수가 시작되기 전에로드 할 시간이 없기 때문이라고 생각합니다. 누구든지 스크립트 내에서 다음 기능을 연기 할 수있는 스크립트를 알고 있습니까? "SheetFlush"와 "attachSendPDF"함수 사이. 스크립트의 사본은 다음과 같습니다 :스크립트 내에서 지연 기능이 필요합니다.
function SheetFlush(worksheet) {
worksheet = worksheet || SpreadsheetApp.getActive();
var sheets = worksheet.getSheets();
SpreadsheetApp.flush();
}
function attachSendPDF() {
var ssID = SpreadsheetApp.getActiveSpreadsheet().getId();
var sheetName = SpreadsheetApp.getActiveSpreadsheet().getName();
var email = ("[email protected]");
var subject = "Master Update";
var body = "Team, here is the Master Update.";
var todaysDate = new Date();
var subjectDate = subject+" "+todaysDate
//this is three level authorization
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");
//even better code
//oauthConfig.setConsumerKey(ScriptProperties.getProperty("consumerKey"));
//oauthConfig.setConsumerSecret(ScriptProperties.getProperty("consumerSecret"));
var requestData = {
"method": "GET",
"oAuthServiceName": "google",
"oAuthUseToken": "always"
};
//"&gid=0&fit to width=true" part is for pdf to b in portrait mode and gid part exports only first sheet . u could have all sheets, so dont put any gid or the number of sheet u wish to export
var url = "https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key="
+ ssID + "&exportFormat=pdf&gridlines=true&printtitle=0&size=letter&fzr=true&portrait=0&fitw=true";
var result = UrlFetchApp.fetch(url , requestData);
var contents = result.getContent();
MailApp.sendEmail(email, subjectDate , body, {attachments:[{fileName:sheetName+todaysDate+".pdf", content:contents, mimeType:"application//pdf"}]});
}
`
감사합니다!