/// <summary> /// 导出已选择快递到excel string packgecode, int ispacked, int pageSize, int pageIndex=1 /// </summary> /// <returns></returns> public ActionResult ExportToExcel(int expressid, int ispacked, DateTime?starttime, DateTime?endtime) { DBModel.Common.ComResult res = new DBModel.Common.ComResult(); //if (1==ispacked) //{ // res.Msg = "已导出包裹不能再导"; // res.State = 0; // return Json(res); //} int count = 0; List <ExpressPackgeModel> list = _service.GetExpressPackgeAllList(expressid, ispacked, out count, starttime, endtime); ///导出数据 string mymsg = string.Empty; string filename = "Excel" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls"; string FilePath = "\\DownExcel\\" + filename; // AppDomain.CurrentDomain.BaseDirectory + string expressname = CommService.GetExpressByID(expressid); //bool excisok = ExcelHelper.ListToExcel<ExportViewmodel>(newlist, FilePath, out mymsg); DataTable dt = new DataTable(); dt.Columns.Add("发货时间", typeof(string)); dt.Columns.Add("包裹号", typeof(string)); dt.Columns.Add("客户名", typeof(string)); dt.Columns.Add("客户前地址", typeof(string)); dt.Columns.Add("客户后地址", typeof(string)); dt.Columns.Add("客户电话", typeof(string)); dt.Columns.Add("客户邮编", typeof(string)); dt.Columns.Add("仓库地址", typeof(string)); dt.Columns.Add("仓库邮编", typeof(string)); dt.Columns.Add("店铺名称", typeof(string)); dt.Columns.Add("仓库电话", typeof(string)); dt.Columns.Add("sku", typeof(string)); dt.Columns.Add("打印sku1", typeof(string)); dt.Columns.Add("打印sku2", typeof(string)); dt.Columns.Add("发货类型", typeof(string)); dt.Columns.Add("请求代号", typeof(string)); dt.Columns.Add("请求管理代号", typeof(string)); dt.Columns.Add("运送管理代号", typeof(string)); dt.Columns.Add("客户管理番号", typeof(string)); foreach (var item2 in list) { DataRow dr = dt.NewRow(); dr["发货时间"] = item2.sendtime; dr["包裹号"] = item2.packgecode; dr["客户名"] = item2.custname; dr["客户前地址"] = item2.custaddress1; dr["客户后地址"] = item2.custaddress2; if (item2.custphone.Length < 3)//说明为空 { dr["客户电话"] = item2.custmobile; } else { dr["客户电话"] = item2.custphone; } dr["客户邮编"] = item2.custzip; dr["仓库地址"] = item2.shopaddress; dr["仓库邮编"] = item2.shopzip; dr["店铺名称"] = item2.shopname; dr["仓库电话"] = item2.shopphone; dr["sku"] = item2.sku; dr["打印sku1"] = item2.sku1; dr["打印sku2"] = item2.sku2; if (expressname == "yamato") { dr["发货类型"] = 3; } else if (expressname == "宅急便") { dr["发货类型"] = 0; } else { dr["发货类型"] = 1;//其他暂时为 1 } dr["请求代号"] = item2.daihao; dr["请求管理代号"] = item2.mangagedaihao; dr["运送管理代号"] = item2.senddaihao; dr["客户管理番号"] = item2.packgecode; dt.Rows.Add(dr); } int a = dt.Rows.Count; string error = string.Empty; bool excisok = ExcelHelper.ExcelOutResult(FilePath, dt, "", out error); if (excisok) { res.Msg = "导出成功"; res.State = 1; res.URL = "../DownExcel/" + filename; return(Json(res)); } else { res.Msg = "导出失败"; res.State = 0; return(Json(res)); } }