6

我想在Crystal Report中從ASP.Net製作報告。我想,當用戶點擊打印時,它應該只顯示保存,打開,另存爲的瀏覽器對話框,並且應該保存PDF,或者應該出現Crystal Report打印預覽,我不想先在Viewer中顯示報告,然後點擊按鈕獲得打印或PDF,我只需要點擊asp按鈕,我有所有的參數的想法,並知道如何做出報告,我的問題是隻是不顯示查看器,並從一個窗體的ASP按鈕報告的PDF或打印預覽對話框打印。我已經使用.Net for Crystal Report的Export方法,但它不起作用。Crystal Report直接另存爲PDF,而不是查看

回答

2

這裏是解決方案,您正在尋找:

http://www.c-sharpcorner.com/UploadFile/mahesh/ExportCRtoPDF10062006161918PM/ExportCRtoPDF.aspx

下面是從網站報價:

以下步驟將引導你達到相同的:

將水晶報表(.cr)文件添加到您的ASP.NET應用程序。 在頁面級別添加報表實例。

昏暗報告作爲MyReport =新MyReport

填充報告上Page_Init數據

昏暗DS作爲數據集=的GetData()

report.SetDataSource(DS)

出口報告

report.ExportToHttpResponse(ExportFormatType.PortableDocFormat,響應,假,「ExportedReport」)

如果你想爲其他格式格式的報表,只需改變ExportFormatType枚舉值>你想要的格式。

如果您希望下載報告,則只需將第4步中的> ExportToHttpResponse方法的第三個參數更改爲True。

4

您可以通過使用水晶報表和一段代碼生成一個PDF ....

  • 第一:生成一個水晶報表按您的要求。

  • 二:使用下面的代碼來生成PDF:

    • 廣場下面的名字空間的代碼頁

      Imports CrystalDecisions.CrystalReports.Engine 
      Imports CrystalDecisions.Shared 
      
    • 變量聲明頂部

      Dim CrReport As New CrystalReport1() // Report Name 
      Dim CrExportOptions As ExportOptions 
      Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions() 
      Dim CrFormatTypeOptions as New PdfRtfWordFormatOptions() 
      
    • 設置目標路徑和文件名

      CrDiskFileDestinationOptions.DiskFileName = "c:\RichText.pdf" 
      
    • 指定頁面範圍(可選)

      crFormatTypeOptions.FirstPageNumber = 1 // Start Page in the Report 
      crFormatTypeOptions.LastPageNumber = 3 // End Page in the Report 
      crFormatTypeOptions.UsePageRange = True 
      
    • 設置導出選項

      CrExportOptions = crReport.ExportOptions 
      
      With CrExportOptions 
      
      // Set the destination to a disk file 
      .ExportDestinationType = ExportDestinationType.DiskFile 
      
      // Set the format to PDF 
      .ExportFormatType = ExportFormatType.PortableDocFormat 
      
      // Set the destination options to DiskFileDestinationOptions object 
      .DestinationOptions = CrDiskFileDestinationOptions 
      .FormatOptions = crFormatTypeOptions 
      
      End With 
      
    • 陷阱出口出現的任何錯誤

      Try 
          // Export the report 
          CrReport.Export() 
      Catch err As Exception 
          MessageBox.Show(err.ToString()) 
      End Try 
      

多數民衆贊成它....現在你已經準備好創建報告的PDF。