Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 谷歌表单+;应用程序脚本+;Webapps:提取和编辑现有行数据并更新行_Javascript_Google Apps Script_Google Sheets - Fatal编程技术网

Javascript 谷歌表单+;应用程序脚本+;Webapps:提取和编辑现有行数据并更新行

Javascript 谷歌表单+;应用程序脚本+;Webapps:提取和编辑现有行数据并更新行,javascript,google-apps-script,google-sheets,Javascript,Google Apps Script,Google Sheets,您好,我正在尝试从与所选ID号匹配的行中提取google工作表中的数据,以编辑数据,然后单击“更新”按钮,以便在google工作表中更新匹配的行。这里是指向我的google工作表的链接 这是我的gs代码 function doGet(request) { return HtmlService.createTemplateFromFile('Index').evaluate(); } /* @Include JavaScript and CSS Files */ function i

您好,我正在尝试从与所选ID号匹配的行中提取google工作表中的数据,以编辑数据,然后单击“更新”按钮,以便在google工作表中更新匹配的行。这里是指向我的google工作表的链接

这是我的gs代码

  function doGet(request) {
  return HtmlService.createTemplateFromFile('Index').evaluate();
 
}

/* @Include JavaScript and CSS Files */
function include(filename) {
  return HtmlService.createHtmlOutputFromFile(filename)
      .getContent();
}
/* @Process Form */



function getCustDetail(search) {
  
  var ss = SpreadsheetApp.getActive()
  var ws = ss.getSheetByName("Data");
  var idvCustData = ws.getRange(2,1,ws.getLastRow(),8).getValues();
  var custIdList = idvCustData.map(function(r){ return r[0]; });
  var custDateList = idvCustData.map(function(r){ return r[2]; });
  var custclientList = idvCustData.map(function(r){ return r[3]; });
  var custlocationList = idvCustData.map(function(r){ return r[4]; });
  var custother1List = idvCustData.map(function(r){ return r[5]; });
  var custother2List = idvCustData.map(function(r){ return r[6]; });
 
  
  
  var searchPostion = custIdList.indexOf(search);
  var custDetail = {};
  custDetail.custId = custIdList[searchPostion];
  custDetail.custDate = custDateList[searchPostion];
  custDetail.custclient = custclientList[searchPostion];
  custDetail.custlocation = custlocationList[searchPostion];
  custDetail.custother1 = custother1List[searchPostion];
  custDetail.custother2 = custother2List[searchPostion];

  Logger.log(searchPostion);
  Logger.log(custDetail);
  Logger.log(search);
  
  if (searchPostion > -1){
  
  return  custDetail;
   
  } else {
    return '-';
 }
}
<script>
  // Prevent forms from submitting.
  function preventFormSubmit() {
    var forms = document.querySelectorAll('form');
    for (var i = 0; i < forms.length; i++) {
      forms[i].addEventListener('submit', function(event) {
      event.preventDefault();
      
      });
    }
  }
  window.addEventListener('load', preventFormSubmit);  
  
  function handleFormSubmit(formObject) {
    google.script.run.processForm(formObject);
    document.getElementById("myForm").reset();
    
  
 }           

//Retrieve Customer
function getCustomer() {
  
  var searchId = document.getElementById("Id").value;
  
 if (searchId != ""){
    google.script.run.withSuccessHandler(custDetail).getCustDetail(searchId);
  } 
  
}

//Success Handler
function custDetail(){

  document.getElementById("Id").innerHTML = cust.Id;
  document.getElementById("Date").innerHTML = cust.Date;
  document.getElementById("client").innerHTML = cust.client;
  document.getElementById("location").innerHTML = cust.location;
  document.getElementById("other1").innerHTML = cust.other1;
  document.getElementById("other2").innerHTML = cust.other2;

  M.updateTextFields();
  
}
</script>
    <!DOCTYPE html>
<html>
    <head>
        <base target="_top">
        <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js" integrity="sha384-xrRywqdh3PHs8keKZN+8zzc5TX0GRTLCcmivcbNJWm2rs5C8PRhcEn3czEjhAO9o" crossorigin="anonymous"></script>
        
    
    <?!= include('JavaScript'); ?>
    <?!= include('CSS'); ?>
    
    <!-- Select2 CDN -->
        <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/css/select2.min.css" rel="stylesheet" />
        <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/js/select2.min.js"></script>
        
        
     <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
     <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
     <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>   
   
   
   
   
     <!-- CSS only -->
    <link rel="stylesheet" href= "https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
        integrity= "sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z"
        crossorigin="anonymous"> 
  
    <!-- JS, Popper.js, jquery and jQuery autocomplete -->
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"
        integrity= "sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" 
        crossorigin="anonymous"> 
    </script> 
    <script src= "https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"
        integrity= "sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN"
        crossorigin="anonymous"> 
    </script> 
    <script src= "https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"
        integrity= "sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV"
        crossorigin="anonymous"> 
    </script>   

    </head>
   
      <body>
        <div class="container">
            <div class="row">
                <div class="col-12">
                    <form id="myForm" onsubmit="handleFormSubmit(this)">
                      <p class="h4 mb-4 text-center">Ticket Form</p>
                      
                      
           <div class="form-row">
           
           
           
           

              
               <div class="form-group col-md-2">
               <label for="Id">ID</label>
               <input type="text" class="form-control" id="Id" name ="Id">
              </div>
              
             
              
              <div class="form-group col-md-2">
               <label for="Date">Ticket Date</label>
               <input type="date" class="form-control" id="Date" name ="Date">
              </div>
              
               <div class="form-group col-md-4">
                 <label for="client">Client</label>
                 <input type="text" class="form-control" id="client" name="client" >
               </div>
                           
               <div class="form-group col-md-4">
                 <label for="location">Location</label>
                 <input type="text" class="form-control" id="location" name="location" >
               </div>
             </div>
   
          <div class="form-row">
             
             <div class="form-group col-md-2">
               <label for="other1">Other1</label>
               <input type="text" class="form-control" id="other1" name ="other1">
              </div>
              
              <div class="form-group col-md-4">
                 <label for="other2">Other2</label>
                 <input type="text" class="form-control" id="other2" name="other2" >
               </div>
                
            </div>
               <hr>
                 <br>
                         
                   <button type="submit" class="btn btn-primary btn-block col-md-4 ">Update</button>
                        
             </form>

                     <br>
                    <div id="output"></div>
                  </div>
                 </div>      
                </div>
               </body>
           
这是我的JS代码

  function doGet(request) {
  return HtmlService.createTemplateFromFile('Index').evaluate();
 
}

/* @Include JavaScript and CSS Files */
function include(filename) {
  return HtmlService.createHtmlOutputFromFile(filename)
      .getContent();
}
/* @Process Form */



function getCustDetail(search) {
  
  var ss = SpreadsheetApp.getActive()
  var ws = ss.getSheetByName("Data");
  var idvCustData = ws.getRange(2,1,ws.getLastRow(),8).getValues();
  var custIdList = idvCustData.map(function(r){ return r[0]; });
  var custDateList = idvCustData.map(function(r){ return r[2]; });
  var custclientList = idvCustData.map(function(r){ return r[3]; });
  var custlocationList = idvCustData.map(function(r){ return r[4]; });
  var custother1List = idvCustData.map(function(r){ return r[5]; });
  var custother2List = idvCustData.map(function(r){ return r[6]; });
 
  
  
  var searchPostion = custIdList.indexOf(search);
  var custDetail = {};
  custDetail.custId = custIdList[searchPostion];
  custDetail.custDate = custDateList[searchPostion];
  custDetail.custclient = custclientList[searchPostion];
  custDetail.custlocation = custlocationList[searchPostion];
  custDetail.custother1 = custother1List[searchPostion];
  custDetail.custother2 = custother2List[searchPostion];

  Logger.log(searchPostion);
  Logger.log(custDetail);
  Logger.log(search);
  
  if (searchPostion > -1){
  
  return  custDetail;
   
  } else {
    return '-';
 }
}
<script>
  // Prevent forms from submitting.
  function preventFormSubmit() {
    var forms = document.querySelectorAll('form');
    for (var i = 0; i < forms.length; i++) {
      forms[i].addEventListener('submit', function(event) {
      event.preventDefault();
      
      });
    }
  }
  window.addEventListener('load', preventFormSubmit);  
  
  function handleFormSubmit(formObject) {
    google.script.run.processForm(formObject);
    document.getElementById("myForm").reset();
    
  
 }           

//Retrieve Customer
function getCustomer() {
  
  var searchId = document.getElementById("Id").value;
  
 if (searchId != ""){
    google.script.run.withSuccessHandler(custDetail).getCustDetail(searchId);
  } 
  
}

//Success Handler
function custDetail(){

  document.getElementById("Id").innerHTML = cust.Id;
  document.getElementById("Date").innerHTML = cust.Date;
  document.getElementById("client").innerHTML = cust.client;
  document.getElementById("location").innerHTML = cust.location;
  document.getElementById("other1").innerHTML = cust.other1;
  document.getElementById("other2").innerHTML = cust.other2;

  M.updateTextFields();
  
}
</script>
    <!DOCTYPE html>
<html>
    <head>
        <base target="_top">
        <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js" integrity="sha384-xrRywqdh3PHs8keKZN+8zzc5TX0GRTLCcmivcbNJWm2rs5C8PRhcEn3czEjhAO9o" crossorigin="anonymous"></script>
        
    
    <?!= include('JavaScript'); ?>
    <?!= include('CSS'); ?>
    
    <!-- Select2 CDN -->
        <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/css/select2.min.css" rel="stylesheet" />
        <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/js/select2.min.js"></script>
        
        
     <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
     <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
     <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>   
   
   
   
   
     <!-- CSS only -->
    <link rel="stylesheet" href= "https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
        integrity= "sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z"
        crossorigin="anonymous"> 
  
    <!-- JS, Popper.js, jquery and jQuery autocomplete -->
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"
        integrity= "sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" 
        crossorigin="anonymous"> 
    </script> 
    <script src= "https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"
        integrity= "sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN"
        crossorigin="anonymous"> 
    </script> 
    <script src= "https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"
        integrity= "sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV"
        crossorigin="anonymous"> 
    </script>   

    </head>
   
      <body>
        <div class="container">
            <div class="row">
                <div class="col-12">
                    <form id="myForm" onsubmit="handleFormSubmit(this)">
                      <p class="h4 mb-4 text-center">Ticket Form</p>
                      
                      
           <div class="form-row">
           
           
           
           

              
               <div class="form-group col-md-2">
               <label for="Id">ID</label>
               <input type="text" class="form-control" id="Id" name ="Id">
              </div>
              
             
              
              <div class="form-group col-md-2">
               <label for="Date">Ticket Date</label>
               <input type="date" class="form-control" id="Date" name ="Date">
              </div>
              
               <div class="form-group col-md-4">
                 <label for="client">Client</label>
                 <input type="text" class="form-control" id="client" name="client" >
               </div>
                           
               <div class="form-group col-md-4">
                 <label for="location">Location</label>
                 <input type="text" class="form-control" id="location" name="location" >
               </div>
             </div>
   
          <div class="form-row">
             
             <div class="form-group col-md-2">
               <label for="other1">Other1</label>
               <input type="text" class="form-control" id="other1" name ="other1">
              </div>
              
              <div class="form-group col-md-4">
                 <label for="other2">Other2</label>
                 <input type="text" class="form-control" id="other2" name="other2" >
               </div>
                
            </div>
               <hr>
                 <br>
                         
                   <button type="submit" class="btn btn-primary btn-block col-md-4 ">Update</button>
                        
             </form>

                     <br>
                    <div id="output"></div>
                  </div>
                 </div>      
                </div>
               </body>
           

//阻止表单提交。
函数preventFormSubmit(){
var forms=document.queryselectoral('form');
对于(var i=0;i
这是我的HTML代码

  function doGet(request) {
  return HtmlService.createTemplateFromFile('Index').evaluate();
 
}

/* @Include JavaScript and CSS Files */
function include(filename) {
  return HtmlService.createHtmlOutputFromFile(filename)
      .getContent();
}
/* @Process Form */



function getCustDetail(search) {
  
  var ss = SpreadsheetApp.getActive()
  var ws = ss.getSheetByName("Data");
  var idvCustData = ws.getRange(2,1,ws.getLastRow(),8).getValues();
  var custIdList = idvCustData.map(function(r){ return r[0]; });
  var custDateList = idvCustData.map(function(r){ return r[2]; });
  var custclientList = idvCustData.map(function(r){ return r[3]; });
  var custlocationList = idvCustData.map(function(r){ return r[4]; });
  var custother1List = idvCustData.map(function(r){ return r[5]; });
  var custother2List = idvCustData.map(function(r){ return r[6]; });
 
  
  
  var searchPostion = custIdList.indexOf(search);
  var custDetail = {};
  custDetail.custId = custIdList[searchPostion];
  custDetail.custDate = custDateList[searchPostion];
  custDetail.custclient = custclientList[searchPostion];
  custDetail.custlocation = custlocationList[searchPostion];
  custDetail.custother1 = custother1List[searchPostion];
  custDetail.custother2 = custother2List[searchPostion];

  Logger.log(searchPostion);
  Logger.log(custDetail);
  Logger.log(search);
  
  if (searchPostion > -1){
  
  return  custDetail;
   
  } else {
    return '-';
 }
}
<script>
  // Prevent forms from submitting.
  function preventFormSubmit() {
    var forms = document.querySelectorAll('form');
    for (var i = 0; i < forms.length; i++) {
      forms[i].addEventListener('submit', function(event) {
      event.preventDefault();
      
      });
    }
  }
  window.addEventListener('load', preventFormSubmit);  
  
  function handleFormSubmit(formObject) {
    google.script.run.processForm(formObject);
    document.getElementById("myForm").reset();
    
  
 }           

//Retrieve Customer
function getCustomer() {
  
  var searchId = document.getElementById("Id").value;
  
 if (searchId != ""){
    google.script.run.withSuccessHandler(custDetail).getCustDetail(searchId);
  } 
  
}

//Success Handler
function custDetail(){

  document.getElementById("Id").innerHTML = cust.Id;
  document.getElementById("Date").innerHTML = cust.Date;
  document.getElementById("client").innerHTML = cust.client;
  document.getElementById("location").innerHTML = cust.location;
  document.getElementById("other1").innerHTML = cust.other1;
  document.getElementById("other2").innerHTML = cust.other2;

  M.updateTextFields();
  
}
</script>
    <!DOCTYPE html>
<html>
    <head>
        <base target="_top">
        <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js" integrity="sha384-xrRywqdh3PHs8keKZN+8zzc5TX0GRTLCcmivcbNJWm2rs5C8PRhcEn3czEjhAO9o" crossorigin="anonymous"></script>
        
    
    <?!= include('JavaScript'); ?>
    <?!= include('CSS'); ?>
    
    <!-- Select2 CDN -->
        <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/css/select2.min.css" rel="stylesheet" />
        <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/js/select2.min.js"></script>
        
        
     <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
     <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
     <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>   
   
   
   
   
     <!-- CSS only -->
    <link rel="stylesheet" href= "https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
        integrity= "sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z"
        crossorigin="anonymous"> 
  
    <!-- JS, Popper.js, jquery and jQuery autocomplete -->
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"
        integrity= "sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" 
        crossorigin="anonymous"> 
    </script> 
    <script src= "https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"
        integrity= "sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN"
        crossorigin="anonymous"> 
    </script> 
    <script src= "https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"
        integrity= "sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV"
        crossorigin="anonymous"> 
    </script>   

    </head>
   
      <body>
        <div class="container">
            <div class="row">
                <div class="col-12">
                    <form id="myForm" onsubmit="handleFormSubmit(this)">
                      <p class="h4 mb-4 text-center">Ticket Form</p>
                      
                      
           <div class="form-row">
           
           
           
           

              
               <div class="form-group col-md-2">
               <label for="Id">ID</label>
               <input type="text" class="form-control" id="Id" name ="Id">
              </div>
              
             
              
              <div class="form-group col-md-2">
               <label for="Date">Ticket Date</label>
               <input type="date" class="form-control" id="Date" name ="Date">
              </div>
              
               <div class="form-group col-md-4">
                 <label for="client">Client</label>
                 <input type="text" class="form-control" id="client" name="client" >
               </div>
                           
               <div class="form-group col-md-4">
                 <label for="location">Location</label>
                 <input type="text" class="form-control" id="location" name="location" >
               </div>
             </div>
   
          <div class="form-row">
             
             <div class="form-group col-md-2">
               <label for="other1">Other1</label>
               <input type="text" class="form-control" id="other1" name ="other1">
              </div>
              
              <div class="form-group col-md-4">
                 <label for="other2">Other2</label>
                 <input type="text" class="form-control" id="other2" name="other2" >
               </div>
                
            </div>
               <hr>
                 <br>
                         
                   <button type="submit" class="btn btn-primary btn-block col-md-4 ">Update</button>
                        
             </form>

                     <br>
                    <div id="output"></div>
                  </div>
                 </div>      
                </div>
               </body>
           

票证表格

身份证件 门票日期 客户 位置 其他1 其他2

更新
修改点:
  • 在Google应用程序脚本端:

    • 当我看到共享电子表格中的脚本时,函数
      getcustdeail
      似乎没有返回值。但是,问题中的脚本返回
      custdail
    • getcustdail
      ,您已经设置了
      search
      的值。因此,在这种情况下,始终使用该值。请小心这个
    • 当使用
      type=“date”
      将该值放入输入时,要求该值为
      yyyy-MM-dd
    • 即使返回
      custdail
      ,Javascript端的
      custdail()
      也不使用参数
    • 即使
      custdeail
      使用来自googleapps脚本端的参数,从googleapps脚本返回的键也与Javascript端的键不同
  • 在Javascript端:

    • 在共享电子表格中,
      var data=google.script.run.getCustDetail()被使用。但是在当前阶段,
      google.script.run
      不返回任何值。请小心这个
    • 如果要将值设置为文本输入,请使用
      value
      而不是
      innerHTML
当上述各点反映到脚本中时,它将变成如下所示

function getCustDetail(search) {
  search = Number(search);
  var ss = SpreadsheetApp.getActive();
  var ws = ss.getSheetByName("Data");
  var idvCustData = ws.getRange(2,1,ws.getLastRow(),8).getValues();
  var custIdList = idvCustData.map(function(r){ return r[0]; });
  var custDateList = idvCustData.map(function(r){ return r[2]; });
  var custclientList = idvCustData.map(function(r){ return r[3]; });
  var custlocationList = idvCustData.map(function(r){ return r[4]; });
  var custother1List = idvCustData.map(function(r){ return r[5]; });
  var custother2List = idvCustData.map(function(r){ return r[6]; });
  var searchPostion = custIdList.indexOf(search);
  var custDetail = {};
  custDetail.Id = custIdList[searchPostion];
  custDetail.Date = custDateList[searchPostion] && Utilities.formatDate(custDateList[searchPostion], Session.getScriptTimeZone(), "yyyy-MM-dd");
  custDetail.client = custclientList[searchPostion];
  custDetail.location = custlocationList[searchPostion];
  custDetail.other1 = custother1List[searchPostion];
  custDetail.other2 = custother2List[searchPostion];
  if (searchPostion > -1){
    return  custDetail;
  } else {
    return null;
  }
}
function custDetail(cust){
  if (cust) {
    document.getElementById("Id").value = cust.Id;
    document.getElementById("Date").value = cust.Date;
    document.getElementById("client").value = cust.client;
    document.getElementById("location").value = cust.location;
    document.getElementById("other1").value = cust.other1;
    document.getElementById("other2").value = cust.other2;
    M.updateTextFields();
  }
}
修改脚本: 谷歌应用程序脚本端: 请修改
getCustDetail
,如下所示

function getCustDetail(search) {
  search = Number(search);
  var ss = SpreadsheetApp.getActive();
  var ws = ss.getSheetByName("Data");
  var idvCustData = ws.getRange(2,1,ws.getLastRow(),8).getValues();
  var custIdList = idvCustData.map(function(r){ return r[0]; });
  var custDateList = idvCustData.map(function(r){ return r[2]; });
  var custclientList = idvCustData.map(function(r){ return r[3]; });
  var custlocationList = idvCustData.map(function(r){ return r[4]; });
  var custother1List = idvCustData.map(function(r){ return r[5]; });
  var custother2List = idvCustData.map(function(r){ return r[6]; });
  var searchPostion = custIdList.indexOf(search);
  var custDetail = {};
  custDetail.Id = custIdList[searchPostion];
  custDetail.Date = custDateList[searchPostion] && Utilities.formatDate(custDateList[searchPostion], Session.getScriptTimeZone(), "yyyy-MM-dd");
  custDetail.client = custclientList[searchPostion];
  custDetail.location = custlocationList[searchPostion];
  custDetail.other1 = custother1List[searchPostion];
  custDetail.other2 = custother2List[searchPostion];
  if (searchPostion > -1){
    return  custDetail;
  } else {
    return null;
  }
}
function custDetail(cust){
  if (cust) {
    document.getElementById("Id").value = cust.Id;
    document.getElementById("Date").value = cust.Date;
    document.getElementById("client").value = cust.client;
    document.getElementById("location").value = cust.location;
    document.getElementById("other1").value = cust.other1;
    document.getElementById("other2").value = cust.other2;
    M.updateTextFields();
  }
}
  • 在这种情况下,它假设电子表格中“A”列的ID始终是数字。请小心这个
Javascript方面: 请修改
custDetail
,如下所示

function getCustDetail(search) {
  search = Number(search);
  var ss = SpreadsheetApp.getActive();
  var ws = ss.getSheetByName("Data");
  var idvCustData = ws.getRange(2,1,ws.getLastRow(),8).getValues();
  var custIdList = idvCustData.map(function(r){ return r[0]; });
  var custDateList = idvCustData.map(function(r){ return r[2]; });
  var custclientList = idvCustData.map(function(r){ return r[3]; });
  var custlocationList = idvCustData.map(function(r){ return r[4]; });
  var custother1List = idvCustData.map(function(r){ return r[5]; });
  var custother2List = idvCustData.map(function(r){ return r[6]; });
  var searchPostion = custIdList.indexOf(search);
  var custDetail = {};
  custDetail.Id = custIdList[searchPostion];
  custDetail.Date = custDateList[searchPostion] && Utilities.formatDate(custDateList[searchPostion], Session.getScriptTimeZone(), "yyyy-MM-dd");
  custDetail.client = custclientList[searchPostion];
  custDetail.location = custlocationList[searchPostion];
  custDetail.other1 = custother1List[searchPostion];
  custDetail.other2 = custother2List[searchPostion];
  if (searchPostion > -1){
    return  custDetail;
  } else {
    return null;
  }
}
function custDetail(cust){
  if (cust) {
    document.getElementById("Id").value = cust.Id;
    document.getElementById("Date").value = cust.Date;
    document.getElementById("client").value = cust.client;
    document.getElementById("location").value = cust.location;
    document.getElementById("other1").value = cust.other1;
    document.getElementById("other2").value = cust.other2;
    M.updateTextFields();
  }
}
注:
  • 修改Web应用脚本时,请将Web应用重新部署为新版本。这样,最新的脚本就会反映到Web应用程序中。请注意这一点。

我可以问一下您的脚本的当前版本吗?是的,我无法获得Web应用程序上显示的数据。谢谢您的回复。我想当我看到你的共享电子表格的脚本时,这些似乎与你的问题不同。哪些脚本是最新的?共享工作表中的脚本是最新的我从该工作表中复制了它不确定为什么会有所不同,但我在共享工作表中。谢谢你的回复。从你的回复中,我提出了一个修改后的脚本作为答案。你能确认一下吗?如果这不是你期望的方向,我很抱歉。谢谢塔奈克那些修改工作很好。如果您能帮我解决另一个问题,那就是在我进行更改并按下更新按钮后,如何让它更新行谢谢again@Yvan谢谢你的回复。我很高兴你的问题解决了。关于你的“另一个问题”,当我发现你的新问题时,我想检查一下。也谢谢你。