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);
                }
            });
  • 相关阅读:
    C# WinForm 取消DataGridView的默认选中Cell 使其不反蓝
    我们 成就了每个我的世界
    [转]firefox与IE的事件处理
    C# WinForm CheckedListBox 使用的相关简单总结
    [书目20090216]高绩效人士的五项管理 李践作品
    [转]asp.net导出Excel/Csv格式数据最优方案(C#)
    [文摘20090201]男女朋友~~需记住亦舒的77句话
    WML 参考手册
    [引]ASP.NET 移动网页 与 如何:使用仿真程序和浏览器在部署移动 Web 应用程序之前对其进行测试
    [文摘20090203]3G知识入门讲座
  • 原文地址:https://www.cnblogs.com/booth/p/2823662.html
Copyright © 2011-2022 走看看