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);
}

 

posted @ 2019-05-21 16:58  CHNMurphy  阅读(455)  评论(0编辑  收藏  举报