public void NoIlocReportList() { string json = string.Empty; string fileName = "無主料位商品報表_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls"; ProductQuery prod = new ProductQuery(); prod.Start = Convert.ToInt32(Request.Params["start"] ?? "0");//用於分頁的變量 prod.Limit = Convert.ToInt32(Request.Params["limit"] ?? "25");//用於分頁的變量 try { if (!string.IsNullOrEmpty(Request.Params["search"])) { prod.vendor_name_simple = Request.Params["search"]; } DataTable dt = new DataTable(); _IiplasMgr = new IplasMgr(mySqlConnectionString); _IiupcMgr = new IupcMgr(mySqlConnectionString); dt = _IiplasMgr.NoIlocReportList(prod); DataTable dtHZ = new DataTable(); string newExcelName = string.Empty; dtHZ.Columns.Add("主料位", typeof(String)); dtHZ.Columns.Add("商品品號", typeof(String)); dtHZ.Columns.Add("品號", typeof(String)); dtHZ.Columns.Add("品名", typeof(String)); dtHZ.Columns.Add("規格", typeof(String)); dtHZ.Columns.Add("廠商", typeof(String)); dtHZ.Columns.Add("條碼", typeof(String)); dtHZ.Columns.Add("內箱長", typeof(String)); dtHZ.Columns.Add("內箱寬", typeof(String)); dtHZ.Columns.Add("內箱高", typeof(String)); //dtHZ.Columns.Add("商品分類", typeof(String)); // pe.inner_pack_len,pe.inner_pack_wid,pe.inner_pack_hgt foreach (DataRow item in dt.Rows) { DataRow dr = dtHZ.NewRow(); dr[0] = item["loc_id"]; dr[1] = item["Product_Id"]; dr[2] = item["item_id"]; dr[3] = item["Product_Name"]; dr[4] = GetProductSpec(item["item_id"].ToString()); dr[5] = item["vendor_name_simple"]; if (string.IsNullOrEmpty(_IiupcMgr.Getupc(item["item_id"].ToString(), "0"))) { dr[6] = "未維護"; } else { dr[6] = " " + _IiupcMgr.Getupc(item["item_id"].ToString(), "0"); } if (string.IsNullOrEmpty(item["inner_pack_len"].ToString())) { dr[7] = "未維護"; } else { dr[7] = item["inner_pack_len"]; } if (string.IsNullOrEmpty(item["inner_pack_wid"].ToString())) { dr[8] = "未維護"; } else { dr[8] = item["inner_pack_wid"]; } if (string.IsNullOrEmpty(item["inner_pack_hgt"].ToString())) { dr[9] = "未維護"; } else { dr[9] = item["inner_pack_hgt"]; } dtHZ.Rows.Add(dr); } MemoryStream ms = ExcelHelperXhf.ExportDT(dtHZ, "無主料位商品報表(寄倉品)" + "_" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")); Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName); Response.BinaryWrite(ms.ToArray()); #region CSV //string[] colname = new string[dtHZ.Columns.Count]; //string filename = "NoIplas.csv"; //newExcelName = Server.MapPath(excelPath) + filename; //for (int i = 0; i < dtHZ.Columns.Count; i++) //{ // colname[i] = dtHZ.Columns[i].ColumnName; //} //if (System.IO.File.Exists(newExcelName)) //{ // System.IO.File.Delete(newExcelName); //} //CsvHelper.ExportDataTableToCsv(dtHZ, newExcelName, colname, true); //IsoDateTimeConverter timeConverter = new IsoDateTimeConverter(); //timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; #endregion } catch (Exception ex) { Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage(); logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message); logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name; log.Error(logMessage); json = "{success:false,data:[]}"; } }