Вы находитесь на странице: 1из 2

here is the code that works fine for exporting Crystal report to Word...

protected void exportReport(CrystalDecisions.CrystalReports.Engine.ReportClass selectedReport, CrystalDecisions.Shared.ExportFormatType eft) { selectedReport.ExportOptions.ExportFormatType = eft; string contentType =""; // Make sure asp.net has create and delete permissions in the directory string tempDir = System.Configuration.ConfigurationSettings.AppSettings["TempDir"]; string tempFileName = Session.SessionID.ToString() + "."; switch (eft) { case CrystalDecisions.Shared.ExportFormatType.PortableDocFormat : tempFileName += "pdf"; contentType = "application/pdf"; break; case CrystalDecisions.Shared.ExportFormatType.WordForWindows : tempFileName+= "doc"; contentType = "application/msword"; break; case CrystalDecisions.Shared.ExportFormatType.Excel : tempFileName+= "xls"; contentType = "application/vnd.ms-excel"; break; case CrystalDecisions.Shared.ExportFormatType.HTML32 : case CrystalDecisions.Shared.ExportFormatType.HTML40 : tempFileName+= "htm"; contentType = "text/html"; CrystalDecisions.Shared.HTMLFormatOptions hop = new CrystalDecisions.Shared.HTMLFormatOptions(); hop.HTMLBaseFolderName = tempDir; hop.HTMLFileName = tempFileName; selectedReport.ExportOptions.FormatOptions = hop; break; } CrystalDecisions.Shared.DiskFileDestinationOptions dfo = new CrystalDecisions.Shared.DiskFileDestinationOptions(); dfo.DiskFileName = tempDir + tempFileName; selectedReport.ExportOptions.DestinationOptions = dfo; selectedReport.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile; selectedReport.Export(); selectedReport.Close(); string tempFileNameUsed; if (eft == CrystalDecisions.Shared.ExportFormatType.HTML32 || eft == CrystalDecisions.Shared.ExportFormatType.HTML40) { string[] fp = selectedReport.FilePath.Split("\\".ToCharArray());

string leafDir = fp[fp.Length-1]; // strip .rpt extension leafDir = leafDir.Substring(0, leafDir.Length 4); tempFileNameUsed = string.Format("{0}{1}\\{2}", tempDir, leafDir, tempFileName); } else tempFileNameUsed = tempDir + tempFileName; Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = contentType; Response.WriteFile(tempFileNameUsed); Response.Flush(); Response.Close(); System.IO.File.Delete(tempFileNameUsed);

************************************************************************ On the access form insert the active x control called Crystal Reports Control. I usually change the name of the control to CrystalReports (go to properties on the control and go to the Other tab). After you insert the active x control on the form type the following code on whatever event you want to generate the report: CrystalReport.Connect = "Provider=SQLOLEDB.1; Server=ServerName; Database=DatabaseName; UID=UserID; PWD=Password" CrystalReport.ReportFileName = "Server path where the report resides" CrystalReport.Action = 0 Make sure you set the permissions on each of your stored procs correctly if you are using stored procs. I have my DBA create a active directory group and put the users in that group. The active directory group then has permission to the stored proc. If the report does not work on the user's desktop then they are missing some of the Crystal Report dlls. They do not need a license to Crystal Reports you just need to copy the correct dlls to their system folder. ************************************************************************

Вам также может понравиться