【第十七篇】easyui-datagrid 导出Excel (在客户端能弹出下载框)

    //导出Excel
function exportExcel(obj) {
var SaleOrderNo = $("#SaleOrderNo").val().trim();
var FoctoryNo = $("#FoctoryNo").val().trim();
var StyleNo = $("#StyleNo").val().trim(); var href = "/Admin/Sale/ExportPressingExcel?1=1";
if (SaleOrderNo == "" && FoctoryNo == "" && StyleNo == "" ) {
href = "/Admin/Sale/ExportPressingExcel";
} else if (SaleOrderNo != "") {
href += "&SaleOrderNo=" + SaleOrderNo;
} else if (FoctoryNo != "") {
href += "&FoctoryNo=" + FoctoryNo;
} else if (StyleNo != "") {
href += "&StyleNo=" + StyleNo;
}
obj.href = href;
}
<a class="btn btn-app" onclick="exportExcel(this)"><i class="fa fa-edit"></i>导出Excel</a>
        /// <summary>
/// 加工单导出Excel
/// </summary>
/// <returns></returns>
public ActionResult ExportPressingExcel()
{
string FoctoryNo = Request.Params["FoctoryNo"];
string StyleNo = Request.Params["StyleNo"];
string SaleOrderNo = Request.Params["SaleOrderNo"]; List<Factory> fList = fService.GetAllFactory();
List<Factory> aList = new List<Factory>();
if (fList != null)
{
for (int i = ; i < fList.Count; i++)
{
Factory f = new Factory();
f.FactoryId = fList[i].FactoryId;
f.FactoryName = fList[i].FactoryName;
f.Tel = fList[i].Tel;
f.Mobile = fList[i].Mobile;
f.MailBox = fList[i].MailBox;
f.Addr = fList[i].Addr; aList.Add(f);
}
} List<Processing> pList = pService.GetExcelProcessing(FoctoryNo, StyleNo, SaleOrderNo);
List<Processing> rList = new List<Processing>();
if (pList != null)
{
for (int i = ; i < pList.Count; i++)
{
Processing s = new Processing();
s.ProcessingId = pList[i].ProcessingId;
s.SaleOrderNo = pList[i].SaleOrderNo;
s.StoneOutNo = pList[i].StoneOutNo;
s.FactoryId = pList[i].FactoryId;
s.ReceiveDate = pList[i].ReceiveDate;
s.CustomerManager = pList[i].CustomerManager;
s.FoctoryUser = pList[i].FoctoryUser;
s.FoctoryNo = pList[i].FoctoryNo;
s.StyleNo = pList[i].StyleNo;
s.CustomerSc = pList[i].CustomerSc;
s.Material = pList[i].Material;
s.Requirement = pList[i].Requirement;
s.SizeJ = pList[i].SizeJ;
switch (pList[i].CompletedStatus)
{
case "":
s.CompletedStatus = "未完成";
break;
case "":
s.CompletedStatus = "完成";
break;
case "":
s.CompletedStatus = "取消";
break;
default:
s.CompletedStatus = "未完成";
break;
} rList.Add(s);
}
} DataTable table = new DataTable();
table.Columns.Add(new DataColumn("工厂单号"));
table.Columns.Add(new DataColumn("订单编号"));
table.Columns.Add(new DataColumn("加工厂"));
table.Columns.Add(new DataColumn("送厂日期"));
table.Columns.Add(new DataColumn("出库单号"));
table.Columns.Add(new DataColumn("客户经理"));
table.Columns.Add(new DataColumn("工厂接收人"));
table.Columns.Add(new DataColumn("款式编号"));
table.Columns.Add(new DataColumn("客户手寸"));
table.Columns.Add(new DataColumn("材质"));
table.Columns.Add(new DataColumn("刻字要求"));
table.Columns.Add(new DataColumn("金重"));
table.Columns.Add(new DataColumn("状态")); foreach (var o in rList)
{
DataRow row = table.NewRow();
row["工厂单号"] = o.FoctoryNo;
row["订单编号"] = o.SaleOrderNo;
foreach (var item in aList)
{
if (o.FactoryId == item.FactoryId)
{
row["加工厂"] = item.FactoryName;
}
}
row["送厂日期"] = o.ReceiveDate;
row["出库单号"] = o.StoneOutNo;
row["客户经理"] = o.CustomerManager;
row["工厂接收人"] = o.FoctoryUser;
row["款式编号"] = o.StyleNo;
row["客户手寸"] = o.CustomerSc;
row["材质"] = o.Material;
row["刻字要求"] = o.Requirement;
row["金重"] = o.SizeJ;
row["状态"] = o.CompletedStatus;
table.Rows.Add(row);
} MemoryStream MemoryStream = new MemoryStream();
HSSFWorkbook work = ExcelHelper.CreateExcelByNPOI(table);
work.Write(MemoryStream);
return File(MemoryStream.GetBuffer(), "application/ms-excel", "加工单-" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");
}

【第十七篇】easyui-datagrid  导出Excel (在客户端能弹出下载框)

---------------------------------------------------------------------------------------------------------

转载请记得说明作者和出处哦-.-
作者:KingDuDu
原文出处:https://www.cnblogs.com/kingdudu/articles/4913250.html

---------------------------------------------------------------------------------------------------------

上一篇:Java如何按空格读取内容


下一篇:POI文件导出至EXCEL,并弹出下载框