zoukankan      html  css  js  c++  java
  • Ajax 导出Excel 方式

    1.使用iframe 加载 使用get方式

    <iframe id="comdownshow" height="0" width="0" frameborder="0" scrolling="no"></iframe>

    2.使用from表单组装 使用post方式

    jQuery.download = function (url, method, Name) {
    jQuery('<form action="' + url + '" method="' + (method || 'post') + '">' +
    '<input type="text" name="AddTimeStrat" value=""/>' +
    '<input type="text" name="AddTimeEnd" value=""/>' +
    '<input type="text" name="Name" value="' + Name + '"/>' +
    '</form>')
    .appendTo('body').submit().remove();
    };

    3.click对象触发

    function Getexcel() {

    //$("#comdownshow").attr("src", "/ModuleContext/EventAccount/Handler/EventAccountManage.ashx?type=ZHZXTJDOWN&AddTimeStrat=" + $("#txtAddTimeStrat").val() + "&AddTimeEnd=" + $("#txtAddTimeEnd").val() + "&Name=" + $("#txtName").val() + "&t=" + new Date().getTime());

    $.download("/ModuleContext/EventAccount/Handler/EventAccountManage.ashx?type=ZHZXTJDOWN","post","城管科");
    }

    4.服务端代码ashx

    string fileName = System.Web.HttpUtility.UrlEncode(name + ".xls");
    context.Response.ContentType = "application/vnd.ms-excel";
    context.Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", fileName));
    context.Response.Clear();
    context.Response.BinaryWrite(ExportStaticDept(list).GetBuffer());

    //ExportStaticDept 生成excel => public MemoryStream ExportStaticDept .....

  • 相关阅读:
    ubuntu 如何进行文件、夹删除等操作
    cuda cudnn anaconda gcc tensorflow 安装及环境配置
    ubuntu16.04系统gcc下降和升级
    关于AJAX 第五篇
    关于AJAX 第四篇
    关于AJAX 第三篇
    关于AJAX 第二篇
    关于AJAX 第一篇
    (转)关于区块链与比特币 来源于嘶吼: http://www.4hou.com/info/news/6152.html
    php 函数
  • 原文地址:https://www.cnblogs.com/linsu/p/7418361.html
Copyright © 2011-2022 走看看