我已经开发了一个边栏表单,可以将值附加到现有电子表格中。
表格有效;但是,新值是从A列开始添加的。我想修改代码以选择要插入附加值的列。用于追加数据的后端代码为:
function addNewRow(rowData) {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const ws = ss.getSheetByName("Recruitment_Contacts");
ws.appendRow([rowData.LnRT,rowData.FnRT,rowData.Gn,rowData.St,rowData.Dtr,rowData.Trn,rowData.Td]);
return true;
}
选择提交按钮后,HTML脚本中用于添加数据的代码为:
function afterButtonClicked(){
var ln = document.getElementById("LnRT");
var fn = document.getElementById("FnRT");
var gn = document.getElementById("Gn");
var st = document.getElementById("St");
var dtr = document.getElementById("Dtr");
var trn = document.getElementById("Trn");
var td = document.getElementById("Td");
var rowData = {LnRT: ln.value, FnRT: fn.value, Gn: gn.value, St: st.value, Dtr: dtr.value, Trn: trn.value, Td: td.value};
google.script.run.withSuccessHandler(afterSubmit).addNewRow(rowData);
}
社区可以提供的任何支持将不胜感激。
谢谢。
为了解决我的问题,我创建了一个服务器端函数“ recruitInfo”,并列出了工作表中的所有列。然后,我在HTML代码中调用了该函数。我曾经向我介绍此过程的视频是Web App-Google Sheets CRUD,第5部分
function addRecruit(recruitInfo){
const ss = SpreadsheetApp.getActiveSpreadsheet();
const ws = ss.getSheetByName("sheetName");
const uniqueIds = ws.getRange(2, 1, ws.getLastRow()-1, 1).getValues();
var maxNum = 0;
uniqueIds.forEach(r => {
maxNum = r[0] > maxNum ? r[0] : maxNum
});
var newID = maxNum + 1;
ws.appendRow([newID,
recruitInfo.lastName,
recruitInfo.firstName])
}
function addRecruit(){
var recruitInfo = {};
recruitInfo.firstName = document.getElementById("firstName").value;
recruitInfo.lastName = document.getElementById("lastName").value;
google.script.run.withSuccessHandler(function(){}).addRecruit(recruitInfo);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句