2017-07-29 59 views
1

我想在我的HTML提交表单输入框中显示googlespreheet单元格“B2”和“C2”值,在输入框“details”和“C2”值中显示“B2”在输入框'数量'中。在HTML表单输入框中显示来自google电子表格的单元格值

下面提到的是我的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> 

三江源提前对您有所帮助。

回答

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; 
} 
+1

这工作就像一个魅力。没有文字表达我的感激之情。感谢一吨丽兹! – Mask

相关问题