У меня есть этот существующий код, он создает документ Google, однако данные не заменяются и не открываются автоматически. Я надеялся, что документ Google тоже будет временным, но они продолжали накапливаться на моем диске каждый раз, когда я его тестировал. Есть ли какой-нибудь возможный способ сделать то, что я пытаюсь сделать?
code.gs
function printRouteSlip(formObject) {
const templateId = "url of my google doc"; // Template Google Doc ID
const templateFile = DriveApp.getFileById(templateId);
// Make a copy of the template
const newDoc = templateFile.makeCopy(`Route Slip for ${formObject.trackingNumber}`);
const newDocId = newDoc.getId();
const doc = DocumentApp.openById(newDocId);
const body = doc.getBody();
// Replace placeholders in the document with actual data from formObject
body.replaceText("{{TimeStamp}}", formObject.timeStamp || "");
body.replaceText("{{TrackingNumber}}", formObject.trackingNumber || "");
body.replaceText("{{DateReceived}}", formObject.dateReceived || "");
body.replaceText("{{ReceivedBy}}", formObject.receivedBy || "");
body.replaceText("{{TransactionType}}", formObject.transactionType || "");
body.replaceText("{{Description}}", formObject.description || "");
body.replaceText("{{OriginOffice}}", formObject.originOffice || "");
body.replaceText("{{ActionTaken}}", formObject.actionTaken || "");
body.replaceText("{{Recipient}}", formObject.recipient || "");
body.replaceText("{{DateTransmitted}}", formObject.dateTransmitted || "");
body.replaceText("{{Remarks}}", formObject.remarks || "");
body.replaceText("{{EmailAddress}}", formObject.email_add || "");
// Save and close the document
doc.saveAndClose();
// Get the document URL
const docUrl = `https://docs.google.com/document/d/${newDocId}/edit`;
// Show the document in a modal for the user to print
const html = HtmlService.createHtmlOutput(`
Click the button below to open and print the document:
[url=${docUrl}]
Open Document
[/url]
window.onunload = function() {
google.script.run.deleteTempFile('${newDocId}');
};
`).setWidth(400).setHeight(200);
SpreadsheetApp.getUi().showModalDialog(html, "Print Route Slip");
У меня есть этот существующий код, он создает документ Google, однако данные не заменяются и не открываются автоматически. Я надеялся, что документ Google тоже будет временным, но они продолжали накапливаться на моем диске каждый раз, когда я его тестировал. Есть ли какой-нибудь возможный способ сделать то, что я пытаюсь сделать? code.gs [code]function printRouteSlip(formObject) { const templateId = "url of my google doc"; // Template Google Doc ID const templateFile = DriveApp.getFileById(templateId);
// Make a copy of the template const newDoc = templateFile.makeCopy(`Route Slip for ${formObject.trackingNumber}`); const newDocId = newDoc.getId(); const doc = DocumentApp.openById(newDocId); const body = doc.getBody();
// Replace placeholders in the document with actual data from formObject body.replaceText("{{TimeStamp}}", formObject.timeStamp || ""); body.replaceText("{{TrackingNumber}}", formObject.trackingNumber || ""); body.replaceText("{{DateReceived}}", formObject.dateReceived || ""); body.replaceText("{{ReceivedBy}}", formObject.receivedBy || ""); body.replaceText("{{TransactionType}}", formObject.transactionType || ""); body.replaceText("{{Description}}", formObject.description || ""); body.replaceText("{{OriginOffice}}", formObject.originOffice || ""); body.replaceText("{{ActionTaken}}", formObject.actionTaken || ""); body.replaceText("{{Recipient}}", formObject.recipient || ""); body.replaceText("{{DateTransmitted}}", formObject.dateTransmitted || ""); body.replaceText("{{Remarks}}", formObject.remarks || ""); body.replaceText("{{EmailAddress}}", formObject.email_add || "");
// Save and close the document doc.saveAndClose();
// Get the document URL const docUrl = `https://docs.google.com/document/d/${newDocId}/edit`;
// Show the document in a modal for the user to print const html = HtmlService.createHtmlOutput(` Click the button below to open and print the document: [url=${docUrl}] Open Document [/url]