zoukankan      html  css  js  c++  java
  • asp.net mvc 导出Excel

            [HttpGet]
            public void ExportNissan(string CheckListNo)
            {
                JObject queryParam;
                if (CheckListNo == null) queryParam = JObject.Parse("{}");
                else queryParam = JObject.Parse(CheckListNo.Replace(" ", ""));
    CostToARTrans artrans
    = new CostToARTrans { CustomerCode = IsEmpity(queryParam["CustomerCode"]), OrderNo = IsEmpity(queryParam["OrderNo"]) }; DataTable dt = CostToARTrans.GetTable(artrans); //region 修改列名 dt.Columns["OrderNo"].ColumnName = "订单号码"; //region 删除不需要数据列 dt.Columns.Remove("CustomerCode"); string fileName = string.Empty; var ie = Request.Headers.Get("User-Agent").IndexOf("MSIE") > 0 || Request.Headers.Get("User-Agent").IndexOf("Trident") > 0; if (ie) fileName = HttpUtility.UrlEncode("test", System.Text.Encoding.UTF8); else fileName = HttpUtility.UrlEncode("test", System.Text.Encoding.UTF8); Response.Charset = "UTF-8"; Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8"); Response.ContentType = "application/ms-excel/msword"; Response.AddHeader("Content-Disposition", "attachment;fileName=" + fileName + ".xls"); Response.BinaryWrite(ExcelHelper.RenderToMemory(dt, "test", true).ToArray()); } private string IsEmpity(object queryParam) { return queryParam != null ? queryParam.ToString() : ""; }
    function fn_ExportNissan()
    {
        var queryParams = {
            CustomerCode: $("#cboCustomer").combobox("getValue"),
            OrderNo: $("#txtOrderNo").textbox("getText")        
        };
        var str_CellInfo = JSON.stringify(queryParams);
        var url = "/TestAPI/ExporteXCEL?CheckListNo=" + str_CellInfo;
        window.open(url);
    }
  • 相关阅读:
    javaScript对象
    javaScript基础
    使用javaScript和JQuery制作经典面试题:光棒效果
    Animate自定义动画
    使用jQuery快速高效制作网页交互特效
    jQuery中绑定事件bind() on() live() one()的异同
    小笔记1(Get请求)

    this关键字
    Eclipse断点调试(下)
  • 原文地址:https://www.cnblogs.com/CHNMurphy/p/10900887.html
Copyright © 2011-2022 走看看