最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
c# 将Datatable数据导出到Excel表格中
时间:2017-07-24 编辑:简简单单 来源:一聚教程网
代码如下 | 复制代码 |
publicFileResult GetExcelFile() { if(Session["beginDate"] !=null) { stringbdate = Session["beginDate"].ToString(); DateTime ld = Convert.ToDateTime(Session["lastDate"].ToString()); DateTime ldate = ld.AddDays(1); stringlldate = ldate.ToString("yyyy-MM-dd"); intptkey = Convert.ToInt32(Session["Process_PTR"]); stringproceSql ="select * from Assay_Process where RKEY="+ptkey; DataTable proceDt = SqlHelper.QueryTable(proceSql); IDataParameter[] iDataTitle =newSqlParameter[3]; iDataTitle[0] =newSqlParameter("@BeginDate", bdate); iDataTitle[1] =newSqlParameter("@LastDate", lldate); iDataTitle[2] =newSqlParameter("@RKEY", ptkey); DataSet dtTitle = SqlHelper.RunProceduresByParameter("pro_GetAssalyInfoByExportPrint", iDataTitle); DataTable dt = dtTitle.Tables[0]; stringoutStr = ExcelExport.outExcel(dt); byte[] fileContents = Encoding.UTF8.GetBytes(outStr.ToString()); returnFile(fileContents,"application/ms-excel",""+ proceDt.Rows[0]["ProcessName"].ToString().Trim() +"化验单据("+ bdate.Trim() +"-"+ lldate.Trim() +").xls"); } else { stringqua_no = Session["quano"].ToString(); IDataParameter[] iDataTitle =newSqlParameter[1]; iDataTitle[0] =newSqlParameter("@Qua_no", qua_no); DataSet dtTitle = SqlHelper.RunProceduresByParameter("pro_GetAssalyInfoByQua_No", iDataTitle); DataTable dt = dtTitle.Tables[0]; stringoutStr = ExcelExport.outExcel(dt); byte[] fileContents = Encoding.UTF8.GetBytes(outStr.ToString()); returnFile(fileContents,"application/ms-excel","化验单据("+ qua_no.Trim()+").xls"); } } |
-
下一个: c#读取XML多级子节点
相关文章
- c# 将Datatable数据导出到Excel表格中 07-24
- C#复制数组的两种方式及效率比较解读 10-24
- ASP.NET Identity用法解析 10-24
- ASP.NET MVC使用Identity增删改查用户介绍 10-24
- C语言中atoi函数模拟实现介绍 10-18
- .Net反向代理组件Yarp用法介绍 10-10