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");
}
}
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持毛票票!
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短