将表单数据提交到Google电子表格中

时间:2017-07-29 12:20:59

标签: javascript google-sheets

我试图通过匹配一些值,将html表格形式的一些数据添加到电子表格中。

但不知何故,提交按钮什么都不做。

Code.gs --->

import UIKit

class ViewController: UIViewController, UIWebViewDelegate {

    @IBOutlet weak var webView: UIWebView!
    override func viewDidLoad() {
        super.viewDidLoad()
        self.webView.delegate = self;
        let url = URL(string: "https://stackoverflow.com")
        debugPrint(url!)
        webView.loadRequest(URLRequest(url: url!))
    }

    // [...]

    func webView(webView: UIWebView!, shouldStartLoadWithRequest request: URLRequest!, navigationType: UIWebViewNavigationType) -> Bool {
        debugPrint("func webView has been called")
        debugPrint(request.url!)
        if navigationType == UIWebViewNavigationType.linkClicked {
            if (request.url!.host! == "stackoverflow.com"){
                return true
            } else {
                //UIApplication.sharedApplication().openURL(request.URL!)
                UIApplication.shared.open(request.url!)
                return false
            }
        }
        return true
    }
}

index.Html ----->

function openInputDialog() {
    var html = HtmlService.createHtmlOutputFromFile('Index').setSandboxMode(HtmlService.SandboxMode.IFRAME);
    SpreadsheetApp.getUi()
        .showModalDialog(html, 'Add Item');
}

function itemAdd(form) {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getSheetByName("Sheet1");
    var lastRow = sheet.getLastRow();
    var match1 = sheet.getRange("B2").getValue();


    for (var i = 0; i = 300; i++)

    {
        if (lastRow - i == match1) {
            sheet.getRange(lastRow - i, 2, 1, 1).setValues(form.details);
            break;
        }

    }
}

我真的很感谢你的帮助。

2 个答案:

答案 0 :(得分:1)

我认为这对你有用。

  /* Show results */
  for (size_t i = 0; i < 3;: ++i)
  {
    if (NOT_IN_USE != numbers[i])
    {
      printf("number[%zu] = %d\n", i, number[i]);
    }

    if (NOT_IN_USE != even[i])
    {
      printf("even[%zu] = %d\n", i, even[i]);
    }

    if (NOT_IN_USE != odd[i])
    {
      printf("odd[%zu] = %d\n", i, odd[i]);
    }
  }
}

答案 1 :(得分:1)

试试这个....替换itemAdd功能

function itemAdd(form) {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getSheetByName("Sheet1");
    var lastRow = sheet.getLastRow();
    var match1 = sheet.getRange("B2").getValue();

    var dataRange = sheet.getRange(1, 1,lastRow).getValues();
    for(var i=0;i<dataRange.length;i++){
        if(dataRange[i][0] == match1){
            sheet.getRange(i+1, 2).setValue(form.details)
        }
    }

}