ExportOptions myExp = new ExportOptions(); if(DDLExportType.SelectedItem.Value==".doc")
{
myExp.ExportFormatType = ExportFormatType.WordForWindows; //导出到Word格式
}
//myExp.ExportFormatType = ExportFormatType.Excel; //导出到Excel格式
else if(DDLExportType.SelectedItem.Value==".pdf")
{
myExp.ExportFormatType = ExportFormatType.PortableDocFormat; //导出到Pdf格式
} //定义导出内容
ExportRequestContext myExpReq = new ExportRequestContext();
myExpReq.ExportInfo = myExp; //产生报表Stream
Stream myReportStream;
myReportStream = report.FormatEngine.ExportToStream(myExpReq);
Response.ClearHeaders();
Response.ClearContent();
if(DDLExportType.SelectedItem.Value==".doc")
{
Response.ContentType = "application/msword";
Response.AddHeader("Content-disposition","attachment; filename=" + DateTime.Now.ToString("yyyyMMddhhssmm") + ".doc");
}
else if(DDLExportType.SelectedItem.Value==".pdf")
{
Response.ContentType = "application/pdf";
Response.AddHeader("Content-disposition","attachment; filename=" + DateTime.Now.ToString("yyyyMMddhhssmm") + ".pdf");
}
byte[] myReportByte = new byte[myReportStream.Length];
myReportStream.Read( myReportByte,0,(int)myReportStream.Length);
Response.BinaryWrite( myReportByte );
Response.Flush();
Response.End();
{
myExp.ExportFormatType = ExportFormatType.WordForWindows; //导出到Word格式
}
//myExp.ExportFormatType = ExportFormatType.Excel; //导出到Excel格式
else if(DDLExportType.SelectedItem.Value==".pdf")
{
myExp.ExportFormatType = ExportFormatType.PortableDocFormat; //导出到Pdf格式
} //定义导出内容
ExportRequestContext myExpReq = new ExportRequestContext();
myExpReq.ExportInfo = myExp; //产生报表Stream
Stream myReportStream;
myReportStream = report.FormatEngine.ExportToStream(myExpReq);
Response.ClearHeaders();
Response.ClearContent();
if(DDLExportType.SelectedItem.Value==".doc")
{
Response.ContentType = "application/msword";
Response.AddHeader("Content-disposition","attachment; filename=" + DateTime.Now.ToString("yyyyMMddhhssmm") + ".doc");
}
else if(DDLExportType.SelectedItem.Value==".pdf")
{
Response.ContentType = "application/pdf";
Response.AddHeader("Content-disposition","attachment; filename=" + DateTime.Now.ToString("yyyyMMddhhssmm") + ".pdf");
}
byte[] myReportByte = new byte[myReportStream.Length];
myReportStream.Read( myReportByte,0,(int)myReportStream.Length);
Response.BinaryWrite( myReportByte );
Response.Flush();
Response.End();
解决方案 »
- 请教浏览某页增加浏览次数的方法
- JavaScript 的写法
- .net企业邮箱的问题
- 怎么取 里面的 邮编:200030
- 异常详细信息: System.InvalidOperationException: ConnectionString 属性尚未初始化
- 紧急求助
- 自定义控件中属性接收数据绑定
- 如何动态改变自定义控件的参数值??
- 如何为CheckBox/List添加客户端的OnClick属性?
- button 怎么传值 就好象给button 加上个参数属性 点击button的时候 可以获得这个button的参数值
- 分享:asp.net办公自动化系统导航源代码
- 讨论: javaScript在aspx中的应用问题(急送分 :) )
Dim FileName As String
Dim CryReport As New ReportDocument Dim LogOnInfo As New CrystalDecisions.Shared.TableLogOnInfo
Dim Disoption As New CrystalDecisions.Shared.DiskFileDestinationOptions
Dim ParaValues As New CrystalDecisions.Shared.ParameterValues
Dim ParaDisValues As New CrystalDecisions.Shared.ParameterDiscreteValue Try
CryReport.Load(Server.MapPath("../EF_Report/Print_Plastic.rpt"))
With LogOnInfo.ConnectionInfo
.ServerName = "localhost"
.UserID = "id"
.Password = "psd"
.DatabaseName = "Database"
End With
For i = 0 To CryReport.Database.Tables.Count - 1
CryReport.Database.Tables.Item(i).ApplyLogOnInfo(LogOnInfo)
Next
FileName = "C:\\" & Session.SessionID.ToString & ".pdf"
CryReport.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat '导出PDF
Cryreport.ExportOptions.ExportFormatType = ExportFormatType.WordForWindows '导出Word
CryReport.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile
Disoption.DiskFileName = FileName
CryReport.ExportOptions.DestinationOptions = Disoption
CryReport.Export() Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "applicaion/pdf" '导出PDF
Response.ContentType ="application/msword";
Response.WriteFile(FileName)
Response.Flush()
Response.Close() 'delete exported files
System.IO.File.Delete(FileName)
按照我这种方法一定行。