Google Forms 创建新文件夹和文档。在新文件夹中放置新文档

发布于 2025-01-11 16:56:26 字数 1781 浏览 0 评论 0原文

嘿,每个人都希望有人可以帮助我。 我目前有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

゛清羽墨安 2025-01-18 16:56:27

创建一个文档并将其保存到文件夹中

您在中间如何处理它取决于您

function createAndSave() {
  const dflr = DriveApp.getFolderById(gobj.globals.testfolderid)
  const t = DocumentApp.openById("template id");
  const d = DocumentApp.create("Nam1");//create new doc and rename
  //do your stuff in here
  const f = d.saveAndClose();
  Drive.Files.update({"parents": [{"id": dflr.getId()}]}, d.getId());
}

您需要启用 Drive API 版本 2 才能运行最后一行

Create a document and save it into a folder

What you do with it in the middle is upto you

function createAndSave() {
  const dflr = DriveApp.getFolderById(gobj.globals.testfolderid)
  const t = DocumentApp.openById("template id");
  const d = DocumentApp.create("Nam1");//create new doc and rename
  //do your stuff in here
  const f = d.saveAndClose();
  Drive.Files.update({"parents": [{"id": dflr.getId()}]}, d.getId());
}

You will need to enable the Drive API version 2 to run the last line

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文