Projektdateien hinzufügen.
This commit is contained in:
64
Gemeinsames/cReportExportierer.vb
Normal file
64
Gemeinsames/cReportExportierer.vb
Normal file
@@ -0,0 +1,64 @@
|
||||
Imports GrapeCity.ActiveReports
|
||||
Imports System.IO
|
||||
Imports System.Windows.Forms
|
||||
Imports GrapeCity.ActiveReports.Document
|
||||
|
||||
Public Class cReportExportierer
|
||||
|
||||
''' <summary>
|
||||
''' Exportiert das angegebene Reportdokument in PDF, Excel oder Word.
|
||||
''' Datei wird ein Standard Speichern-Dialog angezeigt, in dem die o.a. Formate ausgewählt werden können.
|
||||
''' </summary>
|
||||
''' <param name="document">Date zu exportierende Dokument.</param>
|
||||
Public Shared Sub Exportieren(ByVal document As SectionDocument, ByVal Namensvorschlag As String)
|
||||
Try
|
||||
Dim datei As FileInfo = Nothing
|
||||
|
||||
If Not ermittleDateiname(datei, Namensvorschlag) Then
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
Select Case datei.Extension.ToUpper()
|
||||
Case ".pdf".ToUpper()
|
||||
Dim pdfExport1 As New GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport()
|
||||
pdfExport1.Export(document, datei.FullName)
|
||||
Case ".xlsx".ToUpper()
|
||||
Dim xlsExport1 As New GrapeCity.ActiveReports.Export.Excel.Section.XlsExport()
|
||||
xlsExport1.FileFormat = GrapeCity.ActiveReports.Export.Excel.Section.FileFormat.Xlsx
|
||||
xlsExport1.Export(document, datei.FullName)
|
||||
Case ".rtf".ToUpper()
|
||||
Dim rtfExport1 As New GrapeCity.ActiveReports.Export.Word.Section.RtfExport()
|
||||
rtfExport1.Export(document, datei.FullName)
|
||||
Case Else
|
||||
MessageBox.Show("Es würde ein ungültiges Exportformat ausgewählt. Erlaubt sind 'pdf', 'rtf' und 'xlsx'.")
|
||||
Exit Sub
|
||||
End Select
|
||||
|
||||
If MessageBox.Show("Der Export wurde erfolgreich durchgeführt. Soll die Exportdatei jetzt geöffnet werden?", "Export", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) = DialogResult.Yes Then
|
||||
Process.Start(datei.FullName)
|
||||
End If
|
||||
Catch ex As Exception
|
||||
MessageBox.Show("Exportieren fehlgeschlagen. Fehler: " + ex.Message)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Shared Function ermittleDateiname(ByRef datei As FileInfo, ByRef Namensvorschlag As String) As Boolean
|
||||
Using saveDialog As New SaveFileDialog
|
||||
saveDialog.AddExtension = True
|
||||
saveDialog.CheckPathExists = True
|
||||
saveDialog.FileName = Namensvorschlag
|
||||
saveDialog.DefaultExt = ".pdf"
|
||||
saveDialog.Filter = "pdf-Dateien (*.pdf)|*.pdf|Word Dateien (*.rtf)|*.rtf|Excel Dateien (*.xlsx)|*.xlsx"
|
||||
saveDialog.OverwritePrompt = True
|
||||
saveDialog.ValidateNames = True
|
||||
saveDialog.FilterIndex = 0
|
||||
If saveDialog.ShowDialog() = DialogResult.OK Then
|
||||
datei = New FileInfo(saveDialog.FileName)
|
||||
Return True
|
||||
Else
|
||||
Return False
|
||||
End If
|
||||
End Using
|
||||
End Function
|
||||
|
||||
End Class
|
||||
Reference in New Issue
Block a user