我正在从VBA过渡到Google脚本-有点挣扎。我需要一些指导-我希望这个问题不会引起任何疑问。
我有一张表格,用于从一个艺术团体的140名成员那里收集数据。表单更新了电子表格,我使用onFormSubmit(在电子表格中)向用户发送响应电子邮件,以显示他们已提交的内容。我没有使用内置的电子邮件收集/响应工具-我是手动进行的。尚未部署,但在测试中运行良好。
有时,用户会犯错,并且数据需要修复。
鉴于许多用户都没有Google帐户-因此无法登录,因此处理此问题的最佳方法是什么。
非常感谢, 罗伊
答案 0 :(得分:0)
我有一个Google表单,该表单具有提交到电子表格的自定义HTML表单。您可能可以使用它并根据需要对其进行重新加工。
google-script
function openDialog() {
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!';
}
HTML
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<style>
input[type=text], select {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
input[type=submit] {
width: 100%;
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
}
input[type=submit]:hover {
background-color: #45a049;
}
div {
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
}
#hide {
display: none;
}
</style>
<body>
<form onsubmit="sendText(event)" id="form1" >
<div>
<label>Item Number</label>
<input type="text" name="item_number" placeholder="What is the item Number ie. FBY12345"/>
<label>Shop Number</label>
<input type="text" name="shop_number" placeholder="Shop Order Number"/>
<label>Escalation</label>
<select name="escalation" >
<option value="No Escalation ">No Escalation </option>
<option value="72 Hour Escalation ">72 Hour Escalation </option>
<option value="48 Hour Escalation">48 Hour Escalation</option>
<option value="24 Hour Escalation ">24 Hour Escalation </option>
</select>
<label id="hide">Hide1</label>
<input type="text" name="Hide1" id="hide" />
<label>Notes</label>
<input type="text" name="notes" placeholder="Notes"/>
<label>What is the Problem - Select the best option</label>
<select name="problem">
<option value="issue 1">issue 1</option>
<option value="issue 2">issue</option>
<option value="issue 3">issue</option>
<option value="issue 4">issue</option>
<option value="issue 5">issue</option>
<option value="issue 6">issue</option>
<option value="issue 7">issue</option>
<option value="issue 8">issue</option>
<option value="issue 9">issue</option>
<option value="issue 10">issue</option>
</select>
<label>Your Name</label>
<select name="added_by">
<option value="your name">Find Your Name</option>
<option value="name1">name1</option>
<option value="name2">name2</option>
<option value="name3">name3</option>
<option value="name4">name4</option>
<option value="name5">name5</option>
<option value="name6">name6</option>
<option value="name7">name7</option>
<option value="name8">name8</option>
<option value="name9">name9</option>
<option value="name10">name10</option>
</select>
<label>Date on Invoice</label> <br />
<input type="date" name="incoive_date" placeholder="dd/mm/yyyy"/>
<br /> <br />
<label>Location of order </label>
<input type="text" name="location_order" placeholder="FBY Bin 20"/>
<label>Assign to</label>
<select name="user_working">
<option value="name1">name1</option>
<option value="name2">name2</option>
<option value="name3">name3</option>
<option value="name4">name4</option>
<option value="name5">name5</option>
<option value="name6">name6</option>
<option value="name7">name7</option>
<option value="name8">name8</option>
<option value="name9">name9</option>
<option value="name10">name10</option>
</select>
<label >Customer Service Rep on account</label>
<select name="CS_rep">
<option value="name1">name1</option>
<option value="name2">name2</option>
<option value="name3">name3</option>
<option value="name4">name4</option>
<option value="name5">name5</option>
<option value="name6">name6</option>
<option value="name7">name7</option>
<option value="name8">name8</option>
<option value="name9">name9</option>
<option value="name10">name10</option>
</select>
<label>Shipping Request</label>
<select name="shipping">
<option value="None">None</option>
<option value="UPS">UPS</option>
<option value="USPS">USPS</option>
<option value="Asendia">Asendia</option>
</select>
<label>Department</label>
<select name="department">
<option value="Your Sheet 1">Your Sheet 1</option>
<option value="Your Sheet 2">Your Sheet 2</option>
<option value="Your Sheet 3">Your Sheet 3</option>
<option value="Your Sheet 4">Your Sheet 4</option>
<option value="Your Sheet 5">Your Sheet 5</option>
<option value="Your Sheet 6">Your Sheet 6</option>
<option value="Your Sheet 7">Your Sheet 7</option>
</select>
</div>
<div>
<input type="submit" id="submit-form" value="Submit">
</div>
</form>
<script>
function sendText(e) {
e.preventDefault();
var data = {
item_number: e.target['item_number'].value,
shop_number: e.target['shop_number'].value,
escalation: e.target['escalation'].value,
Hide1: e.target['Hide1'].value,
notes: e.target['notes'].value,
problem: e.target['problem'].value,
added_by: e.target['added_by'].value,
incoive_date: e.target['incoive_date'].value,
location_order: e.target['location_order'].value,
user_working: e.target['user_working'].value,
CS_rep: e.target['CS_rep'].value,
shipping: e.target['shipping'].value,
department: e.target['department'].value
}
google.script.run.withSuccessHandler(function(response) {
console.log(response);
google.script.host.close()
})
.sendText(data);
}
</script>
</body>
</html>
您需要确保工作表的第一行与HTML和Javascript中的名称标签(name =“ department”)匹配。
这是我的测试表格,因此您可以查看其工作方式 https://docs.google.com/spreadsheets/d/1iWQ40boplJcJmdFg9HNIyOAOrHOjlCRu362LWRdV5y0/edit?usp=sharing
希望这会有所帮助