简体   繁体   English

我正在尝试取消链接,并删除谷歌表单到谷歌工作表链接,然后将其重新链接到同名的新工作表

[英]I am trying to unlink, and delete a google form to google sheet link and then relink it to a new sheet with the same name

Until I added the dummy sheet "none", the new created sheet was not being picked up during the foreach loop.在我添加虚拟表“无”之前,新创建的表在 foreach 循环期间没有被拾取。 However, if the deleted sheet was not the first subsheet in the Google Sheet, it worked fine also.但是,如果删除的工作表不是 Google 工作表中的第一个子工作表,它也可以正常工作。 Not sure why this was happening.不知道为什么会这样。

function clearForm() {
  var deleter = 0;
  var itemsToDelete = form.getItems();
  form.deleteAllResponses();
  form.setShowLinkToRespondAgain(false);
  form.removeDestination();
  itemsToDelete.forEach(function(next) {
    deleter++;
    form.deleteItem(next);
  });

  SpreadsheetApp.openById(currentSheetID).deleteSheet(currentSheet);

  form.setDestination(FormApp.DestinationType.SPREADSHEET, currentSheetID);

  mainSheet.insertSheet("None", 0);

  var ss = mainSheet.getSheets();

  var v = 1;
  ss.forEach(function(next) {
    Logger.log(v++);
    if (next.getName() != "Form Responses 2" && next.getName() !=
      "Form Responses 1" && next.getName() != "None") {
      next.setName(currentSheetName);

    }
  });

SpreadsheetApp.openById(currentSheetID).deleteSheet(mainSheet.getSheetByName(
    "None"));
}

I understand that your goal is to take an existing Form/Sheet pair, delete the Sheet, create a new Sheet and join it to the original Form.我了解您的目标是获取现有的表格/表格对,删除表格,创建新表格并将其加入原始表格。 If my understanding is correct, then you only need some small tweaks in your code to achieve your objective.如果我的理解是正确的,那么您只需要对代码进行一些小的调整即可实现您的目标。

First thing is to change the old response Sheet for the new one.第一件事是将旧的响应表更改为新的响应表。 With Form.getDestinationId() you can get the ID of the old response Sheet (it will be useful later for cleaning up).使用Form.getDestinationId()您可以获得旧响应表的 ID(稍后用于清理)。 Then you could use Form.setDestination() to make the change happen.然后您可以使用Form.setDestination()进行更改。 If you didn't create the new response Sheet yet, you can use SpreadsheetApp.create() to do so.如果您尚未创建新的响应表,则可以使用SpreadsheetApp.create()来执行此操作。

If that ended fine, then you can send the old Sheet to the trash bin using DriveApp.getFileById().isTrashed() and finish this approach.如果结果很好,那么您可以使用DriveApp.getFileById().isTrashed()将旧工作表发送到垃圾箱并完成此方法。 Please, let me know if you have any questions about this process.如果您对此过程有任何疑问,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM