我想显示googlespreadheet cell" B2"和" C2"我的HTML提交表单输入框中的值," B2"在输入框'详细信息'和" C2"输入框中的值'数量'。
下面提到的是我的HTML代码: -
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<br>
<form>
Details:<br>
<input type="text" name="details">
<br> Quantity:
<br>
<input type="text" name="quantity">
<br><br>
<input type="button" value="Submit" onclick="google.script.run
.withSuccessHandler(google.script.host.close)
.itemAdd(this.parentNode)" />
</form>
</html>
提前感谢你的帮助。
答案 0 :(得分:1)
试试这个......
<强> HTML:强>
<head>
<base target="_top">
</head>
<br>
<form>
Details:<br>
<input type="text" name="details" id="details">
<br> Quantity:
<br>
<input type="text" name="quantity" id="quantity">
<br><br>
<input type="button" value="Submit" onclick="google.script.run
.withSuccessHandler(google.script.host.close)
.itemAdd(this.parentNode)" />
</form>
<script>
window.addEventListener('load', populate());
function populate(){
google.script.run.withSuccessHandler(displayValue).fetchValues();
}
function displayValue(data){
document.getElementById("details").value=data[0][0];
document.getElementById("quantity").value=data[0][1];
}
</script>
</html>
<强>脚本:强>
function fetchValues(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Sheet1"); //Enter your sheet Name
var data = sheet.getRange(2,2,1,2).getValues();
return data;
}