c# 将Datatable数据导出到Excel表格中
话不多说,请看代码:
publicFileResultGetExcelFile()
{
if(Session["beginDate"]!=null)
{
stringbdate=Session["beginDate"].ToString();
DateTimeld=Convert.ToDateTime(Session["lastDate"].ToString());
DateTimeldate=ld.AddDays(1);
stringlldate=ldate.ToString("yyyy-MM-dd");
intptkey=Convert.ToInt32(Session["Process_PTR"]);
stringproceSql="select*fromAssay_ProcesswhereRKEY="+ptkey;
DataTableproceDt=SqlHelper.QueryTable(proceSql);
IDataParameter[]iDataTitle=newSqlParameter[3];
iDataTitle[0]=newSqlParameter("@BeginDate",bdate);
iDataTitle[1]=newSqlParameter("@LastDate",lldate);
iDataTitle[2]=newSqlParameter("@RKEY",ptkey);
DataSetdtTitle=SqlHelper.RunProceduresByParameter("pro_GetAssalyInfoByExportPrint",iDataTitle);
DataTabledt=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);
DataSetdtTitle=SqlHelper.RunProceduresByParameter("pro_GetAssalyInfoByQua_No",iDataTitle);
DataTabledt=dtTitle.Tables[0];
stringoutStr=ExcelExport.outExcel(dt);
byte[]fileContents=Encoding.UTF8.GetBytes(outStr.ToString());
returnFile(fileContents,"application/ms-excel","化验单据("+qua_no.Trim()+").xls");
}
}
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持毛票票!
热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短