我應該說我對腳本一無所知。我在網上發現了符合我需求的這個腳本,所以我能夠爲我的項目重新使用它。無論如何,此腳本需要Google提交表單,填充Google文檔模板,將模板複製,轉換爲PDF並放置在我的Google雲端硬盤上的特定文件夾中。回到未來的平日除外節假日
所以我的問題是,我有一個簡單的線,當腳本運行時拉取當前日期,但我也需要一些代碼,可以計算當前日期加上5個工作日(這應該排除週末),但我也需要它來排除定義的假期。任何幫助將不勝感激。
// Work Order
// Get template from Google Docs and name it
var docTemplate = ""; // *** replace with your template ID ***
var docName = "Work Order";
// When Form Gets submitted
function onFormSubmit(e) {
//Get information from form and set as variables
var email_address = "";
var job_name = e.values[1];
var ship_to = e.values[11];
var address = e.values[12];
var order_count = e.values[7];
var program = e.values[2];
var workspace = e.values[3];
var offer = e.values[4];
var sort_1 = e.values[5];
var sort_2 = e.values[6];
var print_services = e.values[10];
var priority = e.values[13];
var notes = e.values[14];
var formattedDate = Utilities.formatDate(new Date(), "EDT", "MM/dd/yyyy");
// Get document template, copy it as a new temp doc, and save the Doc's id
var copyId = DriveApp.getFileById(docTemplate)
.makeCopy(docName + ' for ' + job_name)
.getId();
// Open the temporary document
var copyDoc = DocumentApp.openById(copyId);
// Get the document's body section
var copyBody = copyDoc.getActiveSection();
// Replace place holder keys,in our google doc template
copyBody.replaceText('keyJobName', job_name);
copyBody.replaceText('keyShipTo', ship_to);
copyBody.replaceText('keyAddress', address);
copyBody.replaceText('keyOrderCount', order_count);
copyBody.replaceText('keyProgram', program);
copyBody.replaceText('keyWorkspace', workspace);
copyBody.replaceText('keyOffer', offer);
copyBody.replaceText('keySort1', sort_1);
copyBody.replaceText('keySort2', sort_2);
copyBody.replaceText('keyPrintServices', print_services);
copyBody.replaceText('keyPriority', priority);
copyBody.replaceText('keyNotes', notes);
copyBody.replaceText('keyDate', formattedDate);
copyBody.replaceText('keyDue', expirationDate);
// Save and close the temporary document
copyDoc.saveAndClose();
// Convert temporary document to PDF by using the getAs blob conversion
var pdf = DriveApp.getFileById(copyId).getAs("application/pdf");
// Attach PDF and send the email
var subject = "New Job Submission";
var body = "Here is the work order for " + job_name + "";
MailApp.sendEmail(email_address, subject, body, {
htmlBody: body,
attachments: pdf
});
// Move file to folder
var file = DriveApp.getFileById(copyId);
DriveApp.getFolderById("").addFile(file);
file.getParents().next().removeFile(file);
}
這不是一個免費的寫作服務。你定義的假期列表在哪裏?他們在不同的地方可能有所不同。你有什麼嘗試? – RobG
我在這些論壇和Google論壇上花了一些時間尋找類似的問題,雖然我發現了一些相似之處,但我沒有javascript知識來理解如何將它集成到我自己的項目中。 一個起點將是美國的國定假日,但如果我有一個基本的例子來定義假期,我可以根據需要添加。 此外,我的問題很廣泛,所以我不尋找自定義代碼或任何東西。 – Brandon
「* ...我的問題相當廣泛*」。是。你可以搜索['[javascript] exclude holidays'](https://stackoverflow.com/search?q=%5Bjavascript%5D+exclude+holidays)。 – RobG