22,210
社区成员
发帖
与我相关
我的任务
分享
declare @filename nvarchar(30)
select @filename='Report'+right(replace(convert(date,GETDATE()),'-',''),2)+substring(replace(convert(date,GETDATE()),'-',''),5,2)+substring(replace(convert(date,GETDATE()),'-',''),1,4)+'.csv'
------------------------------------------
declare @strSQL nvarchar(1024)
set @strSQL='bcp "SELECT * from [A] " queryout D:\'+@filename+' -c -T -t","'
print @strSQL
EXEC master..xp_cmdshell @strSQL
导出csv文件,用excel 也可以打开处理
DataTable dt = db.ExecDataTable(sSQL);
gvResult.DataSource = dt;
gvResult.DataBind();
sSQL = @"dbo.spAtt_Month ";
if (bFlag) //可查全部人的
{
sSQL += "'',";
}
else //只能查自己的
{
sSQL += "'" + Utility.RQuote(this.UserID) + "',";
}
sSQL += Utility.Quote(this.ddlATT_MONTH.SelectedValue);
DataTable dt = db.ExecDataTable(sSQL);
if (dt.Rows.Count > 0)
{
string sFileUpload2 = "考勤月统计表" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";
CommonFunction.ExcelHelper.ExportDTtoExcel(dt, "考勤月统计表", Server.MapPath("~/UploadFiles/Del/") + sFileUpload2);
HLResult.NavigateUrl = "~/UploadFiles/Del/" + sFileUpload2;
HLResult.Visible = true;
ScriptManager.RegisterStartupScript(UpdatePanel2, typeof(UpdatePanel), "scriptName", "alert('考勤月统计表导出成功!请点击右边链接下载。')", true);
return;
}
else
{
ScriptManager.RegisterStartupScript(UpdatePanel2, typeof(UpdatePanel), "scriptName", "alert('对不起,没有记录要导出。')", true);
return;
}