






















private void btnOutForWord_Click( object sender, System.EventArgs e )
{
if ( Session["reportname"] != null && Session[Session["reportname"].ToString()] != null )
{
ReportDocument oRpt = new ReportDocument();
oRpt = ( ReportDocument )Session[Session["reportname"].ToString()];
crvMain.ReportSource = oRpt; ![]()
//设置导出选项。
ExportOptions myExp = new ExportOptions();![]()
myExp.ExportFormatType = ExportFormatType.WordForWindows; //导出到Word格式
//myExp.ExportFormatType = ExportFormatType.Excel; //导出到Excel格式
//myExp.ExportFormatType = ExportFormatType.PortableDocFormat; //导出到Pdf格式![]()
//定义导出内容
ExportRequestContext myExpReq = new ExportRequestContext();
myExpReq.ExportInfo = myExp;![]()
//产生报表Stream
Stream myReportStream;
myReportStream = oRpt.FormatEngine.ExportToStream(myExpReq);
Response.ClearHeaders();
Response.ClearContent();![]()
Response.ContentType = "application/msword";
Response.AddHeader("Content-disposition","attachment; filename=" + DateTime.Now.ToString("yyyyMMddhhssmm") + ".doc");![]()
//Response.ContentType = "application/vnd.ms-excel";
//Response.AddHeader("Content-disposition","attachment; filename=" + year.ToString() + "." + month.ToString() + ".xls");![]()
//Response.ContentType = "application/pdf";
//Response.AddHeader("Content-disposition","attachment; filename=" + year.ToString() + "." + month.ToString() + ".pdf");![]()
byte[] myReportByte = new byte[myReportStream.Length];
myReportStream.Read( myReportByte,0,(int)myReportStream.Length );
Response.BinaryWrite( myReportByte );
Response.Flush();
Response.End();
}
}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。