简体   繁体   English

Append 使用 Apps 脚本在 Google Docs 中选定表上的新行

[英]Append a New Row on selected Tables in Google Docs with Apps Script

I have a Google Docs that has 4 tables, each table contains: Number, Date, Session, Name, Year of Class, and Department.我有一个有 4 个表的 Google 文档,每个表包含:数字、日期、Session、姓名、Class 和部门的年份。

So whenever any new google form submitted, it will update and find the docs and the table based on department and date that the respondent choose.因此,每当提交任何新的谷歌表单时,它都会根据受访者选择的部门和日期更新并查找文档和表格。 So the script already able to find the docs and fill the table based on the date, but the problem is it append the arrow on the next day table.所以脚本已经能够找到文档并根据日期填写表格,但问题是第二天表格上的箭头 append 。 Example: the date selected by the respondent is 05/02/2021, so it should also append the 05/02/2021 table right?示例:被访者选择的日期是 05/02/2021,所以应该也是 05/02/2021 表的 append 吧? instead of 06/02/2021.而不是 2021 年 6 月 2 日。

Google Docs tables (before) Google Docs 表格(之前)

Google Docs tables (after a new response) Google Docs 表格(新回复后)

function appendTable(){
    if (pilihan1 == 'Advokasi dan Kesejahteraan Mahasiswa (ADVOKESMA)'){
      var range = bodyJadwalAdvo.findText(screening);
      var searchElement = bodyJadwalAdvo.findElement(DocumentApp.ElementType.TABLE, range);
    } else if (pilihan1 == 'Pengembangan Sumber Daya Mahasiswa (PSDM)'){
      var range = bodyJadwalPsdm.findText(screening);
      var searchElement = bodyJadwalPsdm.findElement(DocumentApp.ElementType.TABLE, range);
    } else if (pilihan1 == 'Informasi dan Komunikasi (INFOKOM)'){
      var range = bodyJadwalInfokom.findText(screening);
      var searchElement = bodyJadwalInfokom.findElement(DocumentApp.ElementType.TABLE, range);
    } else if (pilihan1 == 'Sosial Masyarakat (SOSMA)'){
      var range = bodyJadwalSosma.findText(screening);
      var searchElement = bodyJadwalSosma.findElement(DocumentApp.ElementType.TABLE, range);
    } else if (pilihan1 == 'Bisnis'){
      var range = bodyJadwalSosma.findText(screening);
      var searchElement = bodyJadwalSosma.findElement(DocumentApp.ElementType.TABLE, range);
    }
    element = searchElement.getElement();
    table = element.asTable();
    var tr = table.appendTableRow();
    
    function replaceBodyJadwal(depart){
      if(screening == '05/02/2021'){
        depart.replaceText('{{TanggalA}}', screening);
        depart.replaceText('{{NamaLengkapA}}', namaLengkap);
        depart.replaceText('{{AngkatanA}}', angkatan);
        depart.replaceText('{{Pilihan2A}}', pilihan2);
        tr.appendTableCell(" ");
        tr.appendTableCell("{{TanggalA}}");
        tr.appendTableCell(" ");
        tr.appendTableCell("{{NamaLengkapA}}");
        tr.appendTableCell("{{AngkatanA}}");
        tr.appendTableCell("{{Pilihan2A}}");
      } else if (screening == '06/02/2021'){
        depart.replaceText('{{TanggalB}}', screening);
        depart.replaceText('{{NamaLengkapB}}', namaLengkap);
        depart.replaceText('{{AngkatanB}}', angkatan);
        depart.replaceText('{{Pilihan2B}}', pilihan2);
        tr.appendTableCell(" ");
        tr.appendTableCell("{{TanggalB}}");
        tr.appendTableCell(" ");
        tr.appendTableCell("{{NamaLengkapB}}");
        tr.appendTableCell("{{AngkatanB}}");
        tr.appendTableCell("{{Pilihan2B}}");
      }  else if (screening == '07/02/2021'){
        depart.replaceText('{{TanggalC}}', screening);
        depart.replaceText('{{NamaLengkapC}}', namaLengkap);
        depart.replaceText('{{AngkatanC}}', angkatan);
        depart.replaceText('{{Pilihan2C}}', pilihan2);
        tr.appendTableCell(" ");
        tr.appendTableCell("{{TanggalC}}");
        tr.appendTableCell(" ");
        tr.appendTableCell("{{NamaLengkapC}}");
        tr.appendTableCell("{{AngkatanC}}");
        tr.appendTableCell("{{Pilihan2C}}");
      }  else if (screening == '08/02/2021'){
        depart.replaceText('{{TanggalD}}', screening);
        depart.replaceText('{{NamaLengkapD}}', namaLengkap);
        depart.replaceText('{{AngkatanD}}', angkatan);
        depart.replaceText('{{Pilihan2D}}', pilihan2);
        tr.appendTableCell(" ");
        tr.appendTableCell("{{TanggalD}}");
        tr.appendTableCell(" ");
        tr.appendTableCell("{{NamaLengkapD}}");
        tr.appendTableCell("{{AngkatanD}}");
        tr.appendTableCell("{{Pilihan2D}}");
      }
    }
    if (pilihan1 == 'Advokasi dan Kesejahteraan Mahasiswa (ADVOKESMA)'){
      replaceBodyJadwal(bodyJadwalAdvo); 
    } else if (pilihan1 == 'Pengembangan Sumber Daya Mahasiswa (PSDM)'){
      replaceBodyJadwal(bodyJadwalPsdm);
    } else if (pilihan1 == 'Informasi dan Komunikasi (INFOKOM)'){
      replaceBodyJadwal(bodyJadwalInfokom);
    } else if (pilihan1 == 'Sosial Masyarakat (SOSMA)'){
      replaceBodyJadwal(bodyJadwalSosma);
    } else if (pilihan1 == 'Bisnis'){
      replaceBodyJadwal(bodyJadwalBisnis);
    } 
  }

Solved.解决了。

function cariTabel(bodyJadwalDepartemen){
      if(screening=='05/02/2021'){
        screeningJadwal=null;
        var range = null;
      } else {
          if(screening=='06/02/2021'){
            screeningJadwal='05/02/2021';
          } else if(screening=='07/02/2021'){
            screeningJadwal='06/02/2021';
          } else if(screening=='08/02/2021'){
            screeningJadwal='07/02/2021';
          }
          var range = bodyJadwalDepartemen.findText(screeningJadwal);
      }     
      searchElement = bodyJadwalDepartemen.findElement(DocumentApp.ElementType.TABLE, range);
    }

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

相关问题 Append Google Apps 脚本上的新表格行(1 行 2 列) - Append a New Table Row (1 Row 2 Columns) on Google Apps Script 使用 Apps 脚本将表格从电子表格附加到 Google 文档 - Appending tables to Google Docs from Spreadsheets using Apps Script Google Apps Script Google Sheets Gmail 处理新邮件追加行数组 - Google Apps Script Google Sheets Gmail Processing New Emails Append Row Array 如何在 Google Apps 脚本中动态创建新工作表时 append 第一行数据 - How to append first row data while creating new sheets dynamically in Google Apps Script Google Apps Script - 使用侧边栏表单向电子表格追加一行 - Google Apps Script - Using Sidebar form to append a row to spreadsheet 使用谷歌应用脚本格式化谷歌文档中的关键字 - Format keywords in google docs with google apps script Google Apps脚本中的强行换行(带有Google Form字段的Google文档可在项目符号列表中创建新项目符号) - Hard Line Break in Google Apps Script (Google Docs with Google Form Field to create new bullet in bulleted list) Append Google Apps 脚本中来自表格数据的新幻灯片 - Append New Slides from Sheets Data in Google Apps Script Google Docs Apps Script getBackgroundColor(Offset) - Google Docs Apps Script getBackgroundColor(Offset) Google Apps 脚本 - 如果表中的最后一列,则使用新行粘贴数据 - Google Apps Script - If Last Column in table, then paste data with new row
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM