2010-08-13 97 views

回答

2

只能使用Crystal Reports的再發行的DLL來打開報告文件,並生成與它PDF。

我從來沒有嘗試直接從ASP打開水晶報表庫,但應該沒問題(或者你可以在VB6,如果你可以創建一個COM DLL)在VB6 DLL

一些代碼,我有使用Crystal Reports 9:

Private Sub Export(ReportFile as string) 
    Dim crxReport As Report 
    Set crxReport = Prepare(ReportFile) 

    crxReport.ExportOptions.FormatType = crEFTPortableDocFormat 
    crxReport.ExportOptions.DestinationType = crEDTDiskFile 
    crxReport.ExportOptions.DiskFileName = "C:\export\export.pdf" 
    crxReport.Export (False) 
end sub 


Private Function Prepare(ReportFile as string) As Report 

    Dim CRapp As CRAXDRT.Application 
    Set CRapp = New CRAXDRT.Application 
    Dim crxReport As Report 
    Dim aDatabaseObject As Database 

    Dim aDatabaseTableObject As CRAXDRT.DatabaseTable 
    Dim objConn As ConnectionProperty 


    Set CRapp = New CRAXDRT.Application 
    CRapp.SetLicenseKeycode ("XXXXXXXXXXXXXXXXXXXXXXXX") 
    Set crxReport = CRapp.OpenReport(ReportFile) 

    Set aDatabaseObject = crxReport.Database 
    Set cnn = New ADODB.Connection 
    cnn.ConnectionString = MyConnectionString() 

    Set aDatabaseObject = crxReport.Database 

    For Each aDatabaseTableObject In aDatabaseObject.Tables 
     Dim objCPProperties As CRAXDRT.ConnectionProperties 
     aDatabaseTableObject.DllName = "crdb_ado.dll" 
     Set objCPProperties = aDatabaseTableObject.ConnectionProperties 
     objCPProperties.DeleteAll 
     objCPProperties.Add "Provider", "SQLOLEDB" 
     objCPProperties.Add "Data Source", cnn.Properties.Item("Data Source").Value 
     objCPProperties.Add "Initial Catalog", cnn.Properties.Item("Initial Catalog").Value 
     objCPProperties.Add "User ID", cnn.Properties.Item("User ID").Value 
     objCPProperties.Add "Password", cnn.Properties.Item("Password").Value 
     aDatabaseTableObject.Location = aDatabaseTableObject.Name 
    Next 

    Set Prepare = crxReport 

End Function