解决把水晶报表下载到客户端过程中,出现下载整个页面(.aspx)或者直接载web页中打开word文件的问题!
2004-11-23 09:28
1121 查看
给一段代码,研究一下,希望对遇到这样问题的朋友有所帮助。
这里特别感谢:浩子的无私帮助!
http://www.cnblogs.com/haozidong
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();
}
}
这里特别感谢:浩子的无私帮助!
http://www.cnblogs.com/haozidong
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();
}
}
相关文章推荐
- 困扰中的vs2003启动问题
- 自治应用程序的体系结构
- asp.net2.0 最新的一些更正
- 创建ASP.NET WEB自定义控件——例程3
- ASP.NET WEB自定义控件
- 一段在asp中加密与解密对应的函数
- asp.net设置默认按钮的一种方法(041217更新)
- 关于ASP.Net中的时间处理
- 把岁月当行李 把往事当垃圾(四)
- ASP.NET 页面中水晶报表导出之二
- ADO.net中的DataReader对象
- ASP.NET 页面中水晶报表导出
- asp.net中发送邮件的几种方式
- ASP.NET控件的设计时支持
- ASP.NET 中 Cookie 的基本知识
- 使用 ASP.NET 的验证控件(转)
- 在 ASP.NET 中使用计时器(Timer)
- Windows 2003下不注册组件用ASP发邮件
- 新的学期开始了。。。
- “Visual Studio.net已检测到指定的Web服务器运行的不是Asp.net1.1版。您将无法运行Asp.net Web应用程序或服务”问题的解决方法