2017-07-29 17 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

相關問題