zoukankan      html  css  js  c++  java
  • 提交form到google账户的execl中

    WebService.ashx

    <%@ WebHandler Language="C#" Class="WebService" %>
    
    using System;
    using System.Web;
    using Google.GData.Client;
    using Google.GData.Spreadsheets;
    using System.Configuration;
    using System.Linq;
    
    public class WebService : IHttpHandler {
        
        public void ProcessRequest (HttpContext context) {
            context.Response.ContentType = "text/plain";
    
            string email = context.Request["e"];
            string path = context.Request["c"];
    
            if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(path))
            {
                context.Response.Write("Email is not null");
            }
            else
            {
                InsertRegstrastionDataIntoSpreadsheet(email, path);
                context.Response.Write("Success!!");
            }
            
            
        }
    
        #region Google Spreadsheet Insert
    
        private SpreadsheetsService service;
    
        protected void InsertRegstrastionDataIntoSpreadsheet(string email, string path)
        {
            service = new SpreadsheetsService("GoogleHyundaiWebServiceRegistration_Spreadsheet");
            service.setUserCredentials(ConfigurationManager.AppSettings["google_username"], ConfigurationManager.AppSettings["google_password"]);
            SpreadsheetQuery query = new SpreadsheetQuery();
            SpreadsheetFeed feed = service.Query(query);
    
            SpreadsheetEntry spreadSheetEntry = null;
            foreach (SpreadsheetEntry entry in feed.Entries)
            {
                if (entry.Title.Text == ConfigurationManager.AppSettings["registration_spreadsheet_name"])//此处是google execl名字
    { spreadSheetEntry
    = entry; } } if (spreadSheetEntry != null) { AtomLink link = spreadSheetEntry.Links.FindService(GDataSpreadsheetsNameTable.WorksheetRel, null); WorksheetQuery worksheetQuery = new WorksheetQuery(link.HRef.ToString()); WorksheetFeed workSheetfeed = service.Query(worksheetQuery); WorksheetEntry worksheetEntry = workSheetfeed.Entries.First() as WorksheetEntry; InsertRow(service, worksheetEntry, email, path); } } protected ListEntry InsertRow(SpreadsheetsService service, WorksheetEntry entry, string email,string path) { AtomLink listFeedLink = entry.Links.FindService(GDataSpreadsheetsNameTable.ListRel, null); ListQuery query = new ListQuery(listFeedLink.HRef.ToString()); ListFeed feed = service.Query(query); ListEntry row = new ListEntry(); //这个地方不知道为什么非得要小写LocalName,如果有知道的请通知我下,谢谢
    row.Elements.Add(
    new ListEntry.Custom() { LocalName = "email", Value = email }); row.Elements.Add(new ListEntry.Custom() { LocalName = "country", Value = path }); service.Insert(feed, row); return row; } #endregion public bool IsReusable { get { return false; } } }

    Default.aspx

            <div class="inputbox"><input name="email" type="text" class="required email"><span>Enter your email here...</span></div>
            <div class="submitbox"><input name="send" type="button" class="submit" value="" onClick="enter();"></div>
            <input id="country" type="hidden" value="china" />

    main.js

            var email = $('input[name="email"]').val();
            var country = $('#country').val();
            $.ajax({
                type: "GET",
                url: "/handler/WebService.ashx",
                data: "e="+email+"&c="+country,
                success: function (msg) {
                    alert(msg);
                }
            });
  • 相关阅读:
    git 教程
    gruntjs
    arm linux
    2021最佳迎接元旦的方式是什么!程序员:中国新冠疫苗上市!
    元旦表白神器!C语言实现浪漫烟花表白(有背景音乐+示例源码)
    大学期间,为啥我能学好C语言?只因我做到了这五点!
    为什么都说代码改变世界?是因为这五位程序员创造了未来!
    C++丨常见的四种求最大公约数方法!赶紧收藏!
    【腾讯C++面试题】如何才能获得腾讯的offer?掌握这20道终身受益!
    惊呆了!字节跳动成唯一上榜的中国公司!它是如何做到脱颖而出的?
  • 原文地址:https://www.cnblogs.com/booth/p/2823662.html
Copyright © 2011-2022 走看看