Hi, Did anyone manage to export crystal report to excel ? I have a problem everytime I export to excel format , it ask me to save or open in .ASPX format . What wrong with it ? This is my code :
Dim filePath As String
Dim myReport As ParticptRpt100
Dim DiskOpts As CrystalDecisions.Shared.DiskFileDestinationOptions
myReport = New ParticptRpt100()
DiskOpts = New CrystalDecisions.Shared.DiskFileDestinationOptions()
filePath = "c:\crystalReports\" & Session.SessionID.ToString & ".xls"
myReport.ExportOptions.ExportDestinationType = CrystalDecisions.[Shared].ExportDestinationType.DiskFile
myReport.ExportOptions.ExportFormatType = CrystalDecisions.[Shared].ExportFormatType.Excel
'File Path
DiskOpts.DiskFileName = filePath
myReport.ExportOptions.DestinationOptions = DiskOpts
myReport.Export()
'Output the file to browser
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/vnd.ms-xls"
Response.WriteFile(filePath)
Response.Flush()
Response.Close()
'Delete the file from server
System.IO.File.Delete(filePath)
I managed to output an excel file to a browser by : replacing Response.ContentType = "application/vnd.ms-xls" to Response.ContentType = "application/vnd.ms-excel"
Here is the code I use to export to pdf, Excel, and word. It might work with other formats but I have not had any need to try it. The reports are stored in Reports directory. private void ExportToFormat(ReportDocument crReportDocument, string sFormat, string
sFileNameAppears,string sFileExtension, ExportFormatType expF) { ExportOptions crExportOptions; DiskFileDestinationOptions crDiskFileDestinationOptions; //The path/location where the exported file will be saved string sFileName = sFileNameAppears+System.DateTime.Today.Year+"_"+System.DateTime.Today.Month
+ "_"+System.DateTime.Today.Day+sFileExtension; string exportFilePath = Server.MapPath(".\\Reports\\") + sFileName; //'Set the options for saving the exported file to disk crDiskFileDestinationOptions = new DiskFileDestinationOptions(); crDiskFileDestinationOptions.DiskFileName
= exportFilePath; //'Set the exporting information crExportOptions = crReportDocument.ExportOptions; crExportOptions.DestinationOptions = crDiskFileDestinationOptions; crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; crExportOptions.ExportFormatType
= expF; //Export the report crReportDocument.Export(); //show the report in browser then delete Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = sFormat; Response.AddHeader("content-disposition", "filename=\""+sFileName +"\""); Response.WriteFile(exportFilePath);
Response.Flush(); Response.Close(); System.IO.File.Delete(exportFilePath); Response.End(); } Here is how I call it: - myReport is a string I append when caching the report in case there is more than one report opened at a time: protected void lbExportWord_Click(object
sender, System.EventArgs e) { ReportDocument rd = (ReportDocument)Context.Cache.Get("rd" + myReport); ExportToFormat(rd,"application/word",rd.Name,".doc",ExportFormatType.WordForWindows); Context.Cache.Remove("rd" + myReport.ToString()); } protected void lbExportExcel_Click(object
sender, System.EventArgs e) { ReportDocument rd = (ReportDocument)Context.Cache.Get("rd" + myReport); ExportToFormat(rd,"application/vnd.ms-xls",rd.Name,".xls",ExportFormatType.Excel); Context.Cache.Remove("rd" + myReport.ToString()); } protected void lbExportPDF_Click(object
sender, System.EventArgs e) { ReportDocument rd = (ReportDocument)Context.Cache.Get("rd" + myReport); ExportToFormat(rd,"application/pdf",rd.Name,".pdf",ExportFormatType.PortableDocFormat); Context.Cache.Remove("rd" + myReport.ToString()); }
nicehill
Member
70 Points
14 Posts
export to excel
Aug 20, 2003 08:33 AM|LINK
Dim filePath As String Dim myReport As ParticptRpt100 Dim DiskOpts As CrystalDecisions.Shared.DiskFileDestinationOptions myReport = New ParticptRpt100() DiskOpts = New CrystalDecisions.Shared.DiskFileDestinationOptions() filePath = "c:\crystalReports\" & Session.SessionID.ToString & ".xls" myReport.ExportOptions.ExportDestinationType = CrystalDecisions.[Shared].ExportDestinationType.DiskFile myReport.ExportOptions.ExportFormatType = CrystalDecisions.[Shared].ExportFormatType.Excel 'File Path DiskOpts.DiskFileName = filePath myReport.ExportOptions.DestinationOptions = DiskOpts myReport.Export() 'Output the file to browser Response.ClearContent() Response.ClearHeaders() Response.ContentType = "application/vnd.ms-xls" Response.WriteFile(filePath) Response.Flush() Response.Close() 'Delete the file from server System.IO.File.Delete(filePath)LordHits
Member
520 Points
104 Posts
Re: export to excel
Aug 20, 2003 01:25 PM|LINK
nicehill
Member
70 Points
14 Posts
Re: export to excel
Aug 22, 2003 03:41 AM|LINK
nicehill
Member
70 Points
14 Posts
Re: export to excel
Aug 22, 2003 06:20 AM|LINK
v1rich
Member
100 Points
20 Posts
Re: export to excel
Sep 03, 2003 07:04 PM|LINK