Execl瀵煎嚭绯荤粺
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Execl瀵煎嚭绯荤粺相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/var' title='var'>var
pen param ack urlencode sroll rtt get child鍓嶅彴浠g爜锛?/p>
<button class="btn btn-warning" type="button" onclick="location.href = 鈥?DownExpress/DownExpress2鈥?>
瀵煎嚭鎶ヨ〃
</button>鍚庡彴浠g爜锛?/p>
public void DownExpress2() { DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("搴忓彿", typeof(string))); dt.Columns.Add(new DataColumn("璁″垝鍗曞彿", typeof(string))); dt.Columns.Add(new DataColumn("鍑哄簱鏃ユ湡", typeof(string))); dt.Columns.Add(new DataColumn("瀹㈡埛鍚嶇О", typeof(string))); dt.Columns.Add(new DataColumn("鐘舵€?, typeof(string))); #region 琛ュ~琛ㄧ粨鏋?鏁版嵁 List<SaleOutboundOrderChild> saleoutboundorderchild = new List<SaleOutboundOrderChild>(); if (Session["SaleOutboundOrderChild"] != null) saleoutboundorderchild = (List<SaleOutboundOrderChild>)Session["SaleOutboundOrderChild"]; if (saleoutboundorderchild.Count() == 0) Response.Write("<script type=鈥榯ext/javascript鈥?gt;alert(鈥樻病鏈夋煡璇㈠埌鏁版嵁锛佲€?</script>"); int num = 1; foreach (var item in saleoutboundorderchild) { string TPrice = item.TPrice.ToString(); if (item.SaleOutboundOrder.BackID != null) TPrice = "-" + TPrice; string TypeClassRollName = ""; if (item.TypeClassRoll != null) TypeClassRollName = item.TypeClassRoll.Name; double? Zprice = 0; var m = db.StockInfo.FirstOrDefault(n => n.Code == item.MaterialCoding); if (m != null) Zprice = m.UnitPrice * item.TQuantity; if (item.SaleOutboundOrder.BackHouse == 1) Zprice = -Zprice; string TypeName = ""; if (item.MaterielTwo != null) { TypeName = item.MaterielTwo.TypeName.Replace(" ", ""); } dt.Rows.Add(num++, item.MarketingPlanChild.MarketingPlan.OrderNo, Common.Date(item.SaleOutboundOrder.SaleDate), item.MarketingPlanChild.MarketingPlan.Client.AbbreviationName, item.MarketingPlanChild.PStatus );//琛ュ~鏁版嵁 } string shtnl = ""; for (int a = 0; a < dt.Columns.Count; a++) { shtnl = shtnl + dt.Columns[a] + 鈥榎t鈥? } shtnl = shtnl + " "; for (int i = 0; i < dt.Rows.Count; i++) { for (int j = 0; j < dt.Columns.Count; j++) { shtnl = shtnl + dt.Rows[i][j] + 鈥榎t鈥? } shtnl = shtnl + " "; } DateTime dtime = DateTime.Now; #endregion ComNo.ExportToExcel("application/x-excel", "閿€鍞嚭搴撳崟鏁版嵁.xls", shtnl); }銆€ExportToExcel
/// <summary> /// 瀵煎嚭琛ㄦ牸淇℃伅 /// </summary> /// <param name="FieldType"></param> /// <param name="FileName"></param> /// <param name="dt"></param> public static void ExportToExcel(string FieldType, string FileName, string dt) { System.Web.HttpContext.Current.Response.Charset = "utf-8"; System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8).ToString()); System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); System.Web.HttpContext.Current.Response.ContentType = FieldType; StringWriter tw = new StringWriter(); System.Web.HttpContext.Current.Response.Output.Write(dt); System.Web.HttpContext.Current.Response.Flush(); System.Web.HttpContext.Current.Response.End(); }銆€銆€
以上是关于Execl瀵煎嚭绯荤粺的主要内容,如果未能解决你的问题,请参考以下文章