【发布时间】:2016-10-03 20:50:26
【问题描述】:
我有一个脚本,可以将数据从我称为“表单”的一张表保存到另一张我称为“记录”的表中。当我单击工作簿中设置为按钮的图像时,该函数运行。
function SaveEWSReport() {
//Save and clear the form
var ss2 = SpreadsheetApp.getActive();
var source = ss2.getSheetByName('Form');
var records = ss2.getSheetByName(source.getRange('A1').getValues()); //get the tab to send the save data to.
var val = source.getRange('A20:Q20').getValues(); //get the cells with information to copy (contain information concatenated form dropdown cells in B2 to P19)
// get values from zero indext cells and save to records.
// 0,0=StudentB3.0,1=GradeD2.0,2=Date.0,2=FlagC5.0,3=ReferedByD5.7,0=NotesB9:F15.3,0=TeirB5.5,0=TypeB7. Nulls leave spaces.
var write = [val[0][0], val[0][1],null, val[0][2], val[0][3], null, null, val[0][4], val[0][5], val[0][6], val[0][7],null];
records.appendRow(write);
//Clear the cells for the next use.
source.getRange('D2').clearContent();
source.getRange('B3').clearContent();
source.getRange('B3:D3').mergeAcross(); // this merges the cell to self heal potential user error.
source.getRange('B5').clearContent();
source.getRange('D5').clearContent();
source.getRange('B7').clearContent();
source.getRange('B7:F7').mergeAcross(); // this merges the cell to self heal potential user error.
source.getRange('B9').clearContent();
source.getRange('B9:F15').merge(); // this merges the cell to self heal potential user error.
问题是我将数据追加到新行
records.appendrow(write)
但是,我希望能够覆盖现有行。 例如,如果记录表上写着:
A3 B3 C3
Student 1 , Grade 6 , Note Set
Student 2 , Grade 8 , Note set
Student 3 , Grade 8 , Note set
A7 B7 C7
然后我为学生 2 添加一个新笔记,然后保存。我想看到同样的东西,但它附加了一行,所以它看起来像这样:
A3 B3 C3
Student 1 , Grade 6 , Note Set
Student 2 , Grade 8 , Note set
Student 3 , Grade 8 , Note set
Student 2 , Grade 8 , Note set
A8 B8 C8
所以你看我需要找到一种方法让脚本进行 vlookup 并找到学生 2,以便它可以将新数据写入同一行,但我不知道如何让脚本写入该行而不是而不是追加一个新的。
我希望这是有道理的。我不经常编程,所以我不确定我的措辞是否正确,我已经搜索过解决方案,但我可能在错误的领域进行搜索,因为我有限的知识和经验。如果这需要澄清,请随时询问。
这是一个包含完整脚本的虚拟表格的链接。 https://docs.google.com/spreadsheets/d/1J2rCtSmt_BM6CozO4EBdlj1YL2wtoW4D4gNCsbalO5M/edit?usp=sharing
【问题讨论】:
标签: google-apps-script google-sheets saving-data