Seleziona una pagina

Ecco un semplice script che permette di generare un report in vari formati con un datasource e aprire il file creato:

 
Public Shared Function CreateOpenReport(ByVal ReportName As String, ByVal dsReport As DataSet, ByVal FileName As String, ByVal ExportType As CrystalDecisions.Shared.ExportFormatType) As Boolean
 
    Dim rep As New CrystalDecisions.CrystalReports.Engine.ReportDocument
    Dim ReportPath As String = ""
  
    ReportPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\Reports"
    rep.Load(ReportPath + "\" + ReportName + ".rpt", CrystalDecisions.Shared.OpenReportMethod.OpenReportByTempCopy)
    rep.SetDataSource(dsReport)
 
    Dim FilePath As String = ""
    Dim ExportFileName As String = ""
 
    FilePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\DOCUMENTI"
 
    Select Case ExportType
        Case CrystalDecisions.Shared.ExportFormatType.PortableDocFormat
            ExportFileName = String.Format("{0}\{1}.pdf", FilePath, FileName)
 
        Case CrystalDecisions.Shared.ExportFormatType.CrystalReport
            ExportFileName = String.Format("{0}\{1}.rpt", FilePath, FileName)
        Case CrystalDecisions.Shared.ExportFormatType.Excel
            ExportFileName = String.Format("{0}\{1}.xls", FilePath, FileName)
        Case CrystalDecisions.Shared.ExportFormatType.ExcelRecord
            ExportFileName = String.Format("{0}\{1}.xls", FilePath, FileName)
        Case CrystalDecisions.Shared.ExportFormatType.HTML32, CrystalDecisions.Shared.ExportFormatType.HTML40
            ExportFileName = String.Format("{0}\{1}.html", FilePath, FileName)
        Case CrystalDecisions.Shared.ExportFormatType.RichText
            ExportFileName = String.Format("{0}\{1}.rtf", FilePath, FileName)
        Case CrystalDecisions.Shared.ExportFormatType.WordForWindows
            ExportFileName = String.Format("{0}\{1}.doc", FilePath, FileName)
 
        Case Else
            ExportFileName = String.Format("{0}\{1}.rpt", FilePath, FileName)
 
    End Select
 
  
    If Not System.IO.Directory.Exists(FilePath) Then
        System.IO.Directory.CreateDirectory(FilePath)
    End If
    If System.IO.File.Exists(ExportFileName) Then
        System.IO.File.Delete(ExportFileName)
    End If
    rep.ExportToDisk(ExportType, ExportFileName)
 
    Dim Proc As New System.Diagnostics.Process
 
    Proc.StartInfo.FileName = ExportFileName
    Proc.Start()
 
End Function
 

Altri Articoli

ASP.NET Core custom Middleware
views 224
Nel precedente articolo intitolato ASP.NET Core Middleware abbiamo parlato di cosa sono i middleware ed abbiamo visto come usare i middleware buit-in ...
ASP.NET Core Middleware
views 391
"Middleware are software components that are assembled into an application pipeline to handle requests and responses. Each component chooses whether t...
ASP.NET Core Project Start Up
views 200
Pubblicato nella sezione wiki un nuovo tutorial su ASP.NET Core: ASP.NET Core Project Start Up. Questo tutorial spiega passo passo la creazione di un...
Creare una Applicazione ASP.NET Core con CLI e Vis...
views 326
La nuova versione ASP.NET CORE è ormai arrivata alla RC2 (Release Candidate 2), possiamo dire che i tempi sono maturi e nonostante le continue evoluzi...