Google Forms 创建新文件夹和文档。在新文件夹中放置新文档
嘿,每个人都希望有人可以帮助我。 我目前有一个 Google 表单,可以填充我的电子表格,然后根据该表单自动创建一个文档。 我对此很陌生,所以我似乎无法弄清楚下一部分。 我希望做的是:提交表单后,它会自动在文件夹中创建一个新的子文件夹,然后正在创建的文档进入该新文件夹。 文件夹的名称需要与创建的文档相同。 这是我到目前为止所拥有的。 如果有人可以帮助编码来解决我的问题,我将永远感激不已。
function onOpen() {
const Ui = SpreadsheetApp.getUi();
const menu = Ui.createMenu('autofillDocs');
menu.addItem('Create new Docs','createnewgoogledoc');
menu.addToUi();
}
function createnewgoogledoc(){
const googleDocsTemplate =
DriveApp.getFileById('1zAmqED4EFdwVADHq3xGvEzTzvscTtIMpZOMkzV9Csa8');
const destiationfolder = DriveApp.getFolderById('0AMUCDqCl3x3aUk9PVA');
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Form Responses 1');
const Rows = sheet.getDataRange().getValues();
Rows.forEach(function(row, index) {
if (index === 0) return;
if (row[14]) return;
if (!row[1]) return;
const copy = googleDocsTemplate.makeCopy(row[1] + " " +row[4] + " " +
row[5],destiationfolder);
const doc = DocumentApp.openById(copy.getId());
const body = doc.getBody();
const friendlyDate = new Date(row[0]).toLocaleDateString();
body.replaceText('{{Options}}', row[3]);
body.replaceText('{{Timestamp}}', friendlyDate);
body.replaceText('{{Tag #}}', row[1]);
body.replaceText('{{Item}}', row[6]);
body.replaceText('{{Item 2}}', row[7]);
body.replaceText('{{Tag 2}}', row[1]);
body.replaceText('{{Item 3}}', row[8]);
body.replaceText('{{Tag 3}}', row[1]);
body.replaceText('{{Item 4}}', row[9]);
body.replaceText('{{Tag 4}}', row[1]);
body.replaceText('{{Item 5}}', row[10]);
body.replaceText('{{Tag 5}}', row[1]);
body.replaceText('{{What is the issue}}', row[12]);
body.replaceText('{{SHOP}}', row[13]);
doc.saveAndClose();
const url = doc.getUrl();
sheet.getRange(index + 1, 15).setValue(url);
Logger.log(row)
})
hey everyone hoping some out out there could give me a hand.
I currently have a Google form that fills my spreadsheet and then auto creates a doc based on that.
I am Very new at this so i cant seem to figure out the next part.
What im hopeing to have done is: once the form has been submitted that it auto creates a new sub folder in a folder and then the doc that is being created goes into that new folder.
The name of the folder needs to be the same as the Doc that was created.
here is what i have so far.
If any one could help with the codeing that would fix my issue i would be forever greatfull.
function onOpen() {
const Ui = SpreadsheetApp.getUi();
const menu = Ui.createMenu('autofillDocs');
menu.addItem('Create new Docs','createnewgoogledoc');
menu.addToUi();
}
function createnewgoogledoc(){
const googleDocsTemplate =
DriveApp.getFileById('1zAmqED4EFdwVADHq3xGvEzTzvscTtIMpZOMkzV9Csa8');
const destiationfolder = DriveApp.getFolderById('0AMUCDqCl3x3aUk9PVA');
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Form Responses 1');
const Rows = sheet.getDataRange().getValues();
Rows.forEach(function(row, index) {
if (index === 0) return;
if (row[14]) return;
if (!row[1]) return;
const copy = googleDocsTemplate.makeCopy(row[1] + " " +row[4] + " " +
row[5],destiationfolder);
const doc = DocumentApp.openById(copy.getId());
const body = doc.getBody();
const friendlyDate = new Date(row[0]).toLocaleDateString();
body.replaceText('{{Options}}', row[3]);
body.replaceText('{{Timestamp}}', friendlyDate);
body.replaceText('{{Tag #}}', row[1]);
body.replaceText('{{Item}}', row[6]);
body.replaceText('{{Item 2}}', row[7]);
body.replaceText('{{Tag 2}}', row[1]);
body.replaceText('{{Item 3}}', row[8]);
body.replaceText('{{Tag 3}}', row[1]);
body.replaceText('{{Item 4}}', row[9]);
body.replaceText('{{Tag 4}}', row[1]);
body.replaceText('{{Item 5}}', row[10]);
body.replaceText('{{Tag 5}}', row[1]);
body.replaceText('{{What is the issue}}', row[12]);
body.replaceText('{{SHOP}}', row[13]);
doc.saveAndClose();
const url = doc.getUrl();
sheet.getRange(index + 1, 15).setValue(url);
Logger.log(row)
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个文档并将其保存到文件夹中
您在中间如何处理它取决于您
您需要启用 Drive API 版本 2 才能运行最后一行
Create a document and save it into a folder
What you do with it in the middle is upto you
You will need to enable the Drive API version 2 to run the last line