<legend id='UDFHT'><style id='UDFHT'><dir id='UDFHT'><q id='UDFHT'></q></dir></style></legend>

<small id='UDFHT'></small><noframes id='UDFHT'>

    • <bdo id='UDFHT'></bdo><ul id='UDFHT'></ul>
      <i id='UDFHT'><tr id='UDFHT'><dt id='UDFHT'><q id='UDFHT'><span id='UDFHT'><b id='UDFHT'><form id='UDFHT'><ins id='UDFHT'></ins><ul id='UDFHT'></ul><sub id='UDFHT'></sub></form><legend id='UDFHT'></legend><bdo id='UDFHT'><pre id='UDFHT'><center id='UDFHT'></center></pre></bdo></b><th id='UDFHT'></th></span></q></dt></tr></i><div id='UDFHT'><tfoot id='UDFHT'></tfoot><dl id='UDFHT'><fieldset id='UDFHT'></fieldset></dl></div>

    1. <tfoot id='UDFHT'></tfoot>

        是否可以将 js 变量发送到谷歌表格?(不是表格数据)

        Is it possible to send js variables to google sheets? (Not form data)(是否可以将 js 变量发送到谷歌表格?(不是表格数据))

          • <tfoot id='2y2Ix'></tfoot>
              <tbody id='2y2Ix'></tbody>

                <legend id='2y2Ix'><style id='2y2Ix'><dir id='2y2Ix'><q id='2y2Ix'></q></dir></style></legend>
                • <bdo id='2y2Ix'></bdo><ul id='2y2Ix'></ul>

                  <small id='2y2Ix'></small><noframes id='2y2Ix'>

                  <i id='2y2Ix'><tr id='2y2Ix'><dt id='2y2Ix'><q id='2y2Ix'><span id='2y2Ix'><b id='2y2Ix'><form id='2y2Ix'><ins id='2y2Ix'></ins><ul id='2y2Ix'></ul><sub id='2y2Ix'></sub></form><legend id='2y2Ix'></legend><bdo id='2y2Ix'><pre id='2y2Ix'><center id='2y2Ix'></center></pre></bdo></b><th id='2y2Ix'></th></span></q></dt></tr></i><div id='2y2Ix'><tfoot id='2y2Ix'></tfoot><dl id='2y2Ix'><fieldset id='2y2Ix'></fieldset></dl></div>
                  本文介绍了是否可以将 js 变量发送到谷歌表格?(不是表格数据)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  根据用户在我的网络应用程序上选择的内容,我创建了一些变量.我想将这些变量发送到谷歌表 - 这可能吗?我已经将数据从表单发送到谷歌表格.因为变量是在用户提交表单的同时创建的,所以我想将表单数据以及这些变量放入工作表中.

                  I have some variables that get created depending on what a user selects on my web app. I want to send those variables to a google sheet - is this possible? I already send data from a form to google sheets. Because the variables get created at the same time a user submits the form I want to put the form data as well as those variables into the sheet.

                  这是当前的js(为了简洁起见,左表html):

                  Here is the current js (left form html out to be concise):

                  $('#CompleteOrder').on('click', function(event){
                                          event.preventDefault();
                  
                                          const scriptURL = 'https://script.google.com/macros/s/...................'
                                          const form = document.forms['submit']
                  
                                          fetch(scriptURL, { method: 'POST', body: new FormData(form)})
                                          .then(response => console.log('Success!', response))
                                          .catch(error => console.error('Error!', error.message))
                  
                                    });
                  

                  这里是我想用表单数据添加到谷歌表的变量的js:

                  And here is the js for the variables I want to add to the google sheet with the form data:

                  var ti = 1;
                              $.each(products, function (i) {
                                  var productID = Number(products[i]['id']);
                                  var productImage = products[i]['image'];
                                  var productColor = products[i]['color'];
                                  var productSize = products[i]['size'];
                                  var productName = products[i]['name'];
                                  var productPrice = Number(products[i]['price']);
                                  var productQty = Number(products[i]['qty']);
                  
                                  body = body + '<tr><td><span>' + productName + '</span></td><td><span>' + productColor + '</span></td><td><span>' + productSize + 'L</span></td><td><span data-prefix>$</span><span >' + productPrice + '</span></td><td><span>' + productQty + '</span></td><td><span data-prefix>$</span><span>' + (productPrice * productQty) + '</span></td></tr>';
                                  total = total + (productPrice * productQty);
                  
                  
                              });
                  

                  谢谢

                  我被卡住的地方是如何获取一个 js 变量并发送到谷歌表格.表格工作在那里没有问题.我找不到任何关于如何在不使用标签的情况下将变量发送到工作表的信息.我什至一直在搞乱将对象转换为表单数据.并且没有关于如何将表单数据以及 js 变量发送到同一张表的说明.

                  Where I am stuck is how to take a js variable and send to a google sheet. The form works there is no problem there. I can't find anything on how to send a variable to a sheet without using tags. I've even been messing with converting the object to form data. And no where is there an explanation on how to send form data as well as js variables to the same sheet.

                  Form
                  
                  <form name="submit">
                                              <div class="form-group">
                                                  <label for="cus-name">Name</label>
                                                  <input type="text" name="name" class="form-control form-control" id="cus-name"></input>
                                              </div>
                                              <div class="form-group">
                                                  <label for="cus-address">Street Address</label>
                                                  <input type="text" name="address" class="form-control form-control" id="cus-address"></input>
                                              </div>
                                              <div class="form-group">
                                                  <label for="cus-city">City</label>
                                                  <input type="text" name="city" class="form-control form-control" id="cus-city"></input>
                                              </div>
                                              <div class="form-group">
                                                  <label for="cus-state">Province</label>
                                                  <input type="text" name="province" class="form-control form-control" id="cus-state"></input>
                                              </div>
                                              <div class="form-group">
                                                  <label for="cus-zipcode">Zipcode</label>
                                                  <input type="text" name="zip" class="form-control form-control" id="cus-zipcode"></input>
                                              </div>
                                              <div class="form-group">
                                                  <label for="cus-phone">Phone Number</label>
                                                  <input type="text" name="number" class="form-control form-control" id="cus-phone"></input>
                                              </div>
                                              <div class="form-group">
                                                  <label for="cus-email">Email Address</label>
                                                  <input type="email" name="email" class="form-control form-control" id="cus-email"></input>
                                              </div>
                  
                  
                  
                  
                                      </div>
                                      <div class="modal-footer">
                                          <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
                                          <button type="submit" class="btn btn-success" id="CompleteOrder">Complete Order</button>
                                      </div>
                  
                                                             </form>
                  

                  谷歌脚本

                  var sheetName = 'Sheet1'
                  var scriptProp = PropertiesService.getScriptProperties()
                  
                  function intialSetup () {
                    var activeSpreadsheet = SpreadsheetApp.getActiveSpreadsheet()
                    scriptProp.setProperty('key', activeSpreadsheet.getId())
                  }
                  
                  function doPost (e) {
                    var lock = LockService.getScriptLock()
                    lock.tryLock(10000)
                  
                    try {
                      var doc = SpreadsheetApp.openById(scriptProp.getProperty('key'))
                      var sheet = doc.getSheetByName(sheetName)
                  
                      var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0]
                      var nextRow = sheet.getLastRow() + 1
                  
                      var newRow = headers.map(function(header) {
                        return header === 'timestamp' ? new Date() : e.parameter[header]
                      })
                  
                      sheet.getRange(nextRow, 1, 1, newRow.length).setValues([newRow])
                  
                      return ContentService
                        .createTextOutput(JSON.stringify({ 'result': 'success', 'row': nextRow }))
                        .setMimeType(ContentService.MimeType.JSON)
                    }
                  
                    catch (e) {
                      return ContentService
                        .createTextOutput(JSON.stringify({ 'result': 'error', 'error': e }))
                        .setMimeType(ContentService.MimeType.JSON)
                    }
                  
                    finally {
                      lock.releaseLock()
                    }
                  }
                  

                  推荐答案

                  看来你问题的核心是

                  如何创建 fetch() 的主体参数,使其包含表单数据对象和 JavaScript 变量中的其他值.

                  How to to create the fetch()'s body argument in such way that it includes both the form data object and other values from JavaScript variables.

                  new FormData(form) 返回一个 FormData 对象.

                  new FormData(form) returns a FormData object.

                  要将 HTML 表单中未包含的值添加到现有 FormData,请使用 FormData.append()

                  To add a value not included on the HTML form to an existing FormData use FormData.append()

                  将上述内容应用于代码以添加一个值的一种方法是替换

                  One way to apply the above to the code to add one value is to replace

                  fetch(scriptURL, { method: 'POST', body: new FormData(form)})
                                          .then(response => console.log('Success!', response))
                                          .catch(error => console.error('Error!', error.message))
                  

                  通过类似的方式:

                  var something = 'New value';
                  var fetchBody = new FormData(form);
                  fetchBody.append('newKey',something);
                  fetch(scriptURL, { method: 'POST', body: fetchBody})
                                          .then(response => console.log('Success!', response))
                                          .catch(error => console.error('Error!', error.message))
                  

                  要添加更多变量,请根据需要添加更多 fetchBody.append().

                  To add more variables, add more fetchBody.append() as needed.

                  注意:我还没有测试以上内容.

                  Note: I didn't tested the above yet.

                  相关问题

                  • 将变量附加到FormData

                  参考文献

                  • fetch() 简介

                  这篇关于是否可以将 js 变量发送到谷歌表格?(不是表格数据)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                  问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                  Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  quot;Each child in an array should have a unique key propquot; only on first time render of page(“数组中的每个孩子都应该有一个唯一的 key prop仅在第一次呈现页面时)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                  Ordinals in words javascript(javascript中的序数)
                • <i id='CPbCW'><tr id='CPbCW'><dt id='CPbCW'><q id='CPbCW'><span id='CPbCW'><b id='CPbCW'><form id='CPbCW'><ins id='CPbCW'></ins><ul id='CPbCW'></ul><sub id='CPbCW'></sub></form><legend id='CPbCW'></legend><bdo id='CPbCW'><pre id='CPbCW'><center id='CPbCW'></center></pre></bdo></b><th id='CPbCW'></th></span></q></dt></tr></i><div id='CPbCW'><tfoot id='CPbCW'></tfoot><dl id='CPbCW'><fieldset id='CPbCW'></fieldset></dl></div>

                    <tbody id='CPbCW'></tbody>
                  1. <legend id='CPbCW'><style id='CPbCW'><dir id='CPbCW'><q id='CPbCW'></q></dir></style></legend>
                      • <bdo id='CPbCW'></bdo><ul id='CPbCW'></ul>

                        • <tfoot id='CPbCW'></tfoot>

                          1. <small id='CPbCW'></small><noframes id='CPbCW'>