ReportDocument crReportDocument;
ExportOptions crExportOptions;
DiskFileDestinationOptions crDiskFileDestinationOptions;
string Fname;
crReportDocument=new ReportDocument();
crReportDocument.Load("D:\\Program Files\\Crystal Reports\\Samples\\Reports\\Feature Examples\\Chart.rpt");
Fname="D:\test.pdf";
crDiskFileDestinationOptions=new DiskFileDestinationOptions();
crDiskFileDestinationOptions.DiskFileName=Fname;
crExportOptions=crReportDocument.ExportOptions
With crExportOptions
         .DestinationOptions=crDiskFileDestinationOptions
         .ExportDestinationType=ExportDestinationType.DiskFile
         .ExportFormatType=ExportFormatType.PortableDocFormat
crReportDocument.Export();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType="application/pdf";
Response.WriteFile(Fname);
Response.Flush();
Response.Close();
System.IO.File.Delete(Fname);
以上这段代码,可以直接将水晶报表,导出到一个临时的pdf的文件,在ie中直接打开,利用pdf的打印功能,可以打印出来,完毕后删除此文件

解决方案 »

  1.   

    lilyfirstone(...为户口忙碌中...) :
    如果是导出成Word,Response.ContentType应该怎么写?
      

  2.   

    lilyfirstone(...为户口忙碌中...) :打印完之后没法关闭pdf文件啊
      

  3.   

    以下是将水晶报表导出成word格式,可以直接从IE打印             Dim myExportOptions As CrystalDecisions.Shared.ExportOptions
            Dim myDiskFileDestinationOptions As _
            CrystalDecisions.Shared.DiskFileDestinationOptions
            Dim myExportFile As String
            Dim myReport As New World_Sales_Report
            myExportFile = "c:\windows\temp\report.doc"
            myDiskFileDestinationOptions = New CrystalDecisions.Shared.DiskFileDestinationOptions
            myDiskFileDestinationOptions.DiskFileName = myExportFile
            myExportOptions = myReport.ExportOptions
            With myExportOptions
                .DestinationOptions = myDiskFileDestinationOptions
                .ExportDestinationType = .ExportDestinationType.DiskFile
                .ExportFormatType = .ExportFormatType.WordForWindows
            End With
            myReport.Export()
            Response.ClearContent()
            Response.ClearHeaders()
            Response.ContentType = "application/msword"        
            Response.WriteFile(myExportFile)
            Response.Flush()
            Response.Close()