[英]Custom HTML Form posting to different sheets in google sheets
I have 4 form that I need to post to different sheets. 我有4个表格需要张贴到不同的工作表中。 I have the following code that with let the forms post but only to the current(Active) sheet but I cannot get it to post to a different sheet.
我有以下代码,可以让表单发布但仅发布到当前(活动)工作表,但无法将其发布到其他工作表。
Another option is if I can have one form and depending what department(Sheet Name) you select it would post to that sheet. 另一种选择是,如果我可以拥有一个表格,并根据您选择的部门(表格名称)将其发布到该表格。
function openDialog1() {
var html = HtmlService.createHtmlOutputFromFile('form1.html');
SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
.showModalDialog(html, 'Pop up Form');
}
function openDialog2() {
var html = HtmlService.createHtmlOutputFromFile('form2.html');
SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
.showModalDialog(html, 'Pop up Form');
}
function openDialog3() {
var html = HtmlService.createHtmlOutputFromFile('form3.html');
SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
.showModalDialog(html, 'Pop up Form');
}
function openDialog4() {
var html = HtmlService.createHtmlOutputFromFile('form4.html');
SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
.showModalDialog(html, 'Pop up Form');
}
function doGet(e){
return HtmlService.createHtmlOutputFromFile('index').setTitle('Adding Rows');
}
function doPost(e) {
Logger.log(e);
}
function sendText(data){
var sheet = SpreadsheetApp.getActiveSheet();
sheet.appendRow([data.item_number, data.shop_number, data.escalation, data.Hide1, data.notes, data.problem, data.added_by, data.incoive_date, data.location_order, data.user_working, data.CS_rep, data.shipping, data.department]);
return 'success!';
}
Here is a link to my test Spreadsheet so you can see the HTML and test. 这是我的测试电子表格的链接,因此您可以查看HTML和测试。
https://docs.google.com/spreadsheets/d/1iWQ40boplJcJmdFg9HNIyOAOrHOjlCRu362LWRdV5y0/edit?usp=sharing https://docs.google.com/spreadsheets/d/1iWQ40boplJcJmdFg9HNIyOAOrHOjlCRu362LWRdV5y0/edit?usp=sharing
as seen on your spreadsheet you are using google.script.run.sendText(data)
on each forms. 从电子表格中可以看出,您在每种表单上都使用了
google.script.run.sendText(data)
。 one solution would be to rebuild your function as so. 一种解决方案是照此重建您的功能。
html HTML
<script>
google.script.run.withSuccessHandler(function(response) {
console.log(response);
google.script.host.close()
}).sendText("Your Sheet",data);
</script>
GAS 加油站
function sendText(sheetName, data){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName(sheetName);
sheet.appendRow([data.item_number, data.shop_number, data.escalation, data.Hide1, data.notes, data.problem, data.added_by, data.incoive_date, data.location_order, data.user_working, data.CS_rep, data.shipping, data.department]);
return 'success!';
}
You only have to pass as argument your sheet name. 您只需传递工作表名称作为参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.