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);
                }
            });
  • 相关阅读:
    常见的http状态码
    浅谈!DOCTYPE声明的作用?严格模式与混杂模式的区别?
    异步控制---实现函数asyncAll,在执行完传入数组中func1,func2,func3异步函数后,输出“end”
    Ecmascript 6新特性
    关于数组去重的几种方法-------javascript描述
    关于字符串的一些操作
    写一个将字符串转成驼峰命名的方法
    js作用域之常见笔试题,运行结果题
    CSS3实现图片黑白滤镜居中,hover缩放遮罩的效果
    远程桌面与本地桌面实现文件传输
  • 原文地址:https://www.cnblogs.com/booth/p/2823662.html
Copyright © 2011-2022 走看看