代码之家  ›  专栏  ›  技术社区  ›  Wassim AZIRAR

使用ASP.NET上的Crystal Reports生成报告

  •  1
  • Wassim AZIRAR  · 技术社区  · 14 年前

    在为旅行社预订机票后,我想生成一个 printable report 使用 Crystal Report .

    我正在寻找一种方法。

    有视频教程或类似的东西吗?

    2 回复  |  直到 10 年前
        1
  •  2
  •   Wassim AZIRAR    14 年前
        2
  •  0
  •   Howard Rothenburg    10 年前
    Imports CrystalDecisions
    Imports CrystalDecisions.CrystalReports
    Imports CrystalDecisions.CrystalReports.Engine
    Imports CrystalDecisions.Shared
    Imports System.IO
    
    Public Class _Default
        Inherits System.Web.UI.Page
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
        End Sub
    
        Protected Sub LinkButton1_Click(sender As Object, e As EventArgs) Handles LinkButton1.Click
    
            OpenPDF(Request.ApplicationPath + "/Reports/Report.pdf")
    
        End Sub
    
    
        Private Sub OpenPDF(downloadAsFilename As String)
            Dim RptDoc As New ReportDocument()
            RptDoc.Load(Server.MapPath(Request.ApplicationPath + "/Reports/myreport.rpt"))
            RptDoc.SetDatabaseLogon("user", "password", "server", "database")
    
            Dim stream As New BinaryReader(RptDoc.ExportToStream(CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat))
            Response.ClearContent()
            Response.ClearHeaders()
            Response.ContentType = "application/pdf"
            Response.AddHeader("content-disposition", Convert.ToString("attachment; filename=") & downloadAsFilename)
            Response.AddHeader("content-length", stream.BaseStream.Length.ToString())
            Response.BinaryWrite(stream.ReadBytes(Convert.ToInt32(stream.BaseStream.Length)))
            Response.Flush()
            Response.Close()
        End Sub
    End Class